Changeset View
Changeset View
Standalone View
Standalone View
src/applications/harbormaster/worker/HarbormasterTargetWorker.php
Show All 29 Lines | private function loadBuildTarget() { | ||||
return $target; | return $target; | ||||
} | } | ||||
public function doWork() { | public function doWork() { | ||||
$target = $this->loadBuildTarget(); | $target = $this->loadBuildTarget(); | ||||
$build = $target->getBuild(); | $build = $target->getBuild(); | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
$target->setDateStarted(time()); | |||||
try { | try { | ||||
$status_pending = HarbormasterBuildTarget::STATUS_PENDING; | $status_pending = HarbormasterBuildTarget::STATUS_PENDING; | ||||
if ($target->getTargetStatus() == $status_pending) { | if ($target->getTargetStatus() == $status_pending) { | ||||
$target->setTargetStatus(HarbormasterBuildTarget::STATUS_BUILDING); | $target->setTargetStatus(HarbormasterBuildTarget::STATUS_BUILDING); | ||||
$target->save(); | $target->save(); | ||||
} | } | ||||
$implementation = $target->getImplementation(); | $implementation = $target->getImplementation(); | ||||
$implementation->execute($build, $target); | $implementation->execute($build, $target); | ||||
$next_status = HarbormasterBuildTarget::STATUS_PASSED; | $next_status = HarbormasterBuildTarget::STATUS_PASSED; | ||||
if ($implementation->shouldWaitForMessage($target)) { | if ($implementation->shouldWaitForMessage($target)) { | ||||
$next_status = HarbormasterBuildTarget::STATUS_WAITING; | $next_status = HarbormasterBuildTarget::STATUS_WAITING; | ||||
} | } | ||||
$target->setTargetStatus($next_status); | $target->setTargetStatus($next_status); | ||||
if ($target->isComplete()) { | |||||
$target->setDateCompleted(time()); | |||||
} | |||||
$target->save(); | $target->save(); | ||||
} catch (PhabricatorWorkerYieldException $ex) { | } catch (PhabricatorWorkerYieldException $ex) { | ||||
// If the target wants to yield, let that escape without further | // If the target wants to yield, let that escape without further | ||||
// processing. We'll resume after the task retries. | // processing. We'll resume after the task retries. | ||||
throw $ex; | throw $ex; | ||||
} catch (HarbormasterBuildFailureException $ex) { | } catch (HarbormasterBuildFailureException $ex) { | ||||
// A build step wants to fail explicitly. | // A build step wants to fail explicitly. | ||||
$target->setTargetStatus(HarbormasterBuildTarget::STATUS_FAILED); | $target->setTargetStatus(HarbormasterBuildTarget::STATUS_FAILED); | ||||
$target->setDateCompleted(time()); | |||||
$target->save(); | $target->save(); | ||||
} catch (Exception $ex) { | } catch (Exception $ex) { | ||||
phlog($ex); | phlog($ex); | ||||
try { | try { | ||||
$log = $build->createLog($target, 'core', 'exception'); | $log = $build->createLog($target, 'core', 'exception'); | ||||
$start = $log->start(); | $start = $log->start(); | ||||
$log->append((string)$ex); | $log->append((string)$ex); | ||||
$log->finalize($start); | $log->finalize($start); | ||||
} catch (Exception $log_ex) { | } catch (Exception $log_ex) { | ||||
phlog($log_ex); | phlog($log_ex); | ||||
} | } | ||||
$target->setTargetStatus(HarbormasterBuildTarget::STATUS_FAILED); | $target->setTargetStatus(HarbormasterBuildTarget::STATUS_FAILED); | ||||
$target->setDateCompleted(time()); | |||||
$target->save(); | $target->save(); | ||||
} | } | ||||
id(new HarbormasterBuildEngine()) | id(new HarbormasterBuildEngine()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->setBuild($build) | ->setBuild($build) | ||||
->continueBuild(); | ->continueBuild(); | ||||
} | } | ||||
} | } |