Last active
August 29, 2015 14:11
-
-
Save guywarner/94aaa1e5fee60150f574 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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