Skip to content

Commit

Permalink
Added states for use in pullBundleChunk, refactored to use AsyncRunner
Browse files Browse the repository at this point in the history
  • Loading branch information
cambell-prince committed Jun 29, 2012
1 parent 693c213 commit c337113
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 140 deletions.
3 changes: 0 additions & 3 deletions api/v01/src/BundleHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,6 @@ static function validateAlphaNumeric($str) {
}
}

// TODO store metadata in an mySQL database to keep information about
// transaction activity

// get the offset of the data we've collected
function getOffset() {
$metadata = $this->getMetadata();
Expand Down
98 changes: 50 additions & 48 deletions api/v02/src/BundleHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ class BundleHelper {
private $_transactionId;
private $_basePath;

const State_Start = 'Start';
const State_MakingBundle = 'MakingBundle';
const State_Downloading = 'Downloading';

function __construct($id) {
if(!BundleHelper::validateAlphaNumeric($id)) {
throw new Exception("ValidationException: transId $id did not validate as alpha numeric!");
Expand All @@ -22,56 +26,34 @@ private function getBundleDir() {
return $path;
}

/**
* @return bool
*/
public function exists() {
return file_exists($this->getBundleFileName());
}

function cleanUpFiles() {
if (file_exists($this->getBundleFileName())) {
unlink($this->getBundleFileName());
}
if (file_exists($this->getMetaDataFileName())) {
unlink($this->getMetaDataFileName());
}
if (file_exists($this->getBundleTimeFileName())) {
unlink($this->getBundleTimeFileName());
}
return true;
}

public function isLocked() {
return file_exists($this->getBundleTimeFileName());
}

function isBundleCreated() {
if (file_exists($this->getBundleFileName())) {
return BundleHelper::isBundleFinished($this->getBundleTimeFileName());
}
return false;
}

function isBundleValid() {
if (file_exists($this->getBundleFileName())) {
return BundleHelper::isBundleFinishedAndValid($this->getBundleTimeFileName());
}
}

// static helper functions
// Note: Only used by tests
public static function isBundleFinishedAndValid($bundleTimeFile) {
return BundleHelper::isBundleFinished($bundleTimeFile) && !BundleHelper::bundleFileHasErrors($bundleTimeFile);
}

public static function isBundleFinished($bundleTimeFile) {
$data = file_get_contents($bundleTimeFile);
if (strpos($data, "makebundleprocess") !== false) {
return true;
}
return false;
}

private static function bundleFileHasErrors($bundleTimeFile) {
$data = file_get_contents($bundleTimeFile);
if (strpos($data, "abort") !== false or
strpos($data, "invalid") !== false or
/**
* Checks the hg output in $output. Returns true if error indicators are found.
* @param string $output
* @return bool
*/
public static function bundleOutputHasErrors($output) {
if (strpos($output, "abort") !== false or
strpos($output, "invalid") !== false or
//strpos($data, "invalid") !== false or
strpos($data, "exited with non-zero status 255") !== false) {
strpos($output, "exited with non-zero status 255") !== false) {
return true;
}
return false;
Expand All @@ -84,10 +66,6 @@ public function getBundleBaseFilePath() {
return $this->getBundleDir() . '/' .$this->_transactionId;
}

function getBundleTimeFileName() {
return $this->getBundleBaseFilePath() . ".isFinished";
}

function getBundleFileName() {
return $this->getBundleBaseFilePath() . '.bundle';
}
Expand All @@ -105,11 +83,11 @@ static function validateAlphaNumeric($str) {
}
}

// TODO store metadata in an mySQL database to keep information about
// transaction activity

// get the offset of the data we've collected
function getOffset() {
/**
* Get the start of window.
* @return int
*/
public function getOffset() {
$metadata = $this->getMetadata();
if (array_key_exists('offset', $metadata)) {
return $metadata['offset'];
Expand All @@ -118,12 +96,36 @@ function getOffset() {
}
}

function setOffset($val) {
/**
* Set the start of window
* @param int $val
*/
public function setOffset($val) {
$metadata = $this->getMetadata();
$metadata['offset'] = intval($val);
$this->setMetadata($metadata);
}

/**
* Gets the current state of this transaction
* @return string
*/
public function getState() {
$result = $this->getProp('state');
if (empty($result)) {
$result = self::State_Start;
}
return $result;
}

/**
* Sets the current state of this transaction
* @param string $state
*/
public function setState($state) {
$this->setProp('state', $state);
}

private function getMetadata() {
$filename = $this->getMetaDataFileName();
if (file_exists($filename)) {
Expand Down
Loading

0 comments on commit c337113

Please sign in to comment.