Skip to content

Instantly share code, notes, and snippets.

@guywarner
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guywarner/94aaa1e5fee60150f574 to your computer and use it in GitHub Desktop.
Save guywarner/94aaa1e5fee60150f574 to your computer and use it in GitHub Desktop.
// OLD CODE
// Wait for one minute for data source operation status to be IDLE
// Database operation (add/remove records) is asynchronous
public function waitForIdle($dataSourceId)
{
$end = time() + 60; // up to one minute
while (time() < $end)
{
try
{
$datasource = $this->get($dataSourceId);
if ($datasource[0]->operationStatus != "IDLE")
{
sleep(2);
}
else
{
break;
}
}
catch (Exception $e)
{
// ok
}
}
}
// New
/**
* Wait up to one minute for data source operation status to be IDLE
* Database operation (add/remove records) is asynchronous
*
* @param InternalDataSourceId $datasourceId a data source object containing the id
* @return void
*/
public function waitForIdle(InternalDataSourceId $dataSourceId)
{
$endTime = time() + 60; // up to one minute
while ($this->getDataSourceOperationStatus($dataSourceId) != "IDLE")
{
if (time() < $endTime)
{
break;
}
sleep(2);
}
}
/**
* Gets status of a internal datasource in StrongView
*
* @param InternalDataSourceId $datasourceId a data source object containing the id
* @throws Exception
* @return string
*/
public function getDataSourceOperationStatus(InternalDataSourceId $dataSourceId) {
try
{
$datasource = $this->get($dataSourceId);
return $datasource[0]->operationStatus;
}
catch (Exception $e)
{
throw new Exception($e->getMessage(), 1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment