Changeset View
Changeset View
Standalone View
Standalone View
src/applications/harbormaster/engine/HarbormasterBuildEngine.php
| Show First 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | foreach ($this->getNewBuildTargets() as $target) { | ||||
| 'HarbormasterTargetWorker', | 'HarbormasterTargetWorker', | ||||
| array( | array( | ||||
| 'targetID' => $target->getID(), | 'targetID' => $target->getID(), | ||||
| )); | )); | ||||
| } | } | ||||
| } | } | ||||
| private function updateBuild(HarbormasterBuild $build) { | private function updateBuild(HarbormasterBuild $build) { | ||||
| // TODO: Handle cancellation and restarts. | |||||
| if ($build->getBuildStatus() == HarbormasterBuild::STATUS_PENDING) { | $should_stop = false; | ||||
| $should_resume = false; | |||||
| $should_restart = false; | |||||
| foreach ($build->getUnprocessedCommands() as $command) { | |||||
| switch ($command->getCommand()) { | |||||
| case HarbormasterBuildCommand::COMMAND_STOP: | |||||
| $should_stop = true; | |||||
| $should_resume = false; | |||||
| break; | |||||
| case HarbormasterBuildCommand::COMMAND_RESUME: | |||||
| $should_resume = true; | |||||
| $should_stop = false; | |||||
| break; | |||||
| case HarbormasterBuildCommand::COMMAND_RESTART: | |||||
| $should_restart = true; | |||||
| $should_resume = true; | |||||
| $should_stop = false; | |||||
| break; | |||||
| } | |||||
| } | |||||
| if (($build->getBuildStatus() == HarbormasterBuild::STATUS_PENDING) || | |||||
| ($should_restart)) { | |||||
| $this->destroyBuildTargets($build); | $this->destroyBuildTargets($build); | ||||
| $build->setBuildStatus(HarbormasterBuild::STATUS_BUILDING); | $build->setBuildStatus(HarbormasterBuild::STATUS_BUILDING); | ||||
| $build->save(); | $build->save(); | ||||
| } | } | ||||
| if ($should_resume) { | |||||
| $build->setBuildStatus(HarbormasterBuild::STATUS_BUILDING); | |||||
| $build->save(); | |||||
| } | |||||
| if ($should_stop && !$build->isComplete()) { | |||||
| $build->setBuildStatus(HarbormasterBuild::STATUS_STOPPED); | |||||
| $build->save(); | |||||
| } | |||||
| foreach ($build->getUnprocessedCommands() as $command) { | |||||
| $command->delete(); | |||||
| } | |||||
| $build->attachUnprocessedCommands(array()); | |||||
| if ($build->getBuildStatus() == HarbormasterBuild::STATUS_BUILDING) { | if ($build->getBuildStatus() == HarbormasterBuild::STATUS_BUILDING) { | ||||
| return $this->updateBuildSteps($build); | $this->updateBuildSteps($build); | ||||
| } | } | ||||
| } | } | ||||
| private function destroyBuildTargets(HarbormasterBuild $build) { | private function destroyBuildTargets(HarbormasterBuild $build) { | ||||
| $targets = id(new HarbormasterBuildTargetQuery()) | $targets = id(new HarbormasterBuildTargetQuery()) | ||||
| ->setViewer($this->getViewer()) | ->setViewer($this->getViewer()) | ||||
| ->withBuildPHIDs(array($build->getPHID())) | ->withBuildPHIDs(array($build->getPHID())) | ||||
| ->execute(); | ->execute(); | ||||
| Show All 20 Lines | private function updateBuildSteps(HarbormasterBuild $build) { | ||||
| $failed = array(); | $failed = array(); | ||||
| $waiting = array(); | $waiting = array(); | ||||
| foreach ($steps as $step) { | foreach ($steps as $step) { | ||||
| $step_targets = idx($targets, $step->getPHID(), array()); | $step_targets = idx($targets, $step->getPHID(), array()); | ||||
| if ($step_targets) { | if ($step_targets) { | ||||
| $is_complete = true; | $is_complete = true; | ||||
| foreach ($step_targets as $target) { | foreach ($step_targets as $target) { | ||||
| // TODO: Move this to a top-level "status" field on BuildTarget. | if (!$target->isComplete()) { | ||||
| if (!$target->getDetail('__done__')) { | |||||
| $is_complete = false; | $is_complete = false; | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| $is_failed = false; | $is_failed = false; | ||||
| foreach ($step_targets as $target) { | foreach ($step_targets as $target) { | ||||
| // TODO: Move this to a top-level "status" field on BuildTarget. | if ($target->isFailed()) { | ||||
| if ($target->getDetail('__failed__')) { | |||||
| $is_failed = true; | $is_failed = true; | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| $is_waiting = false; | $is_waiting = false; | ||||
| } else { | } else { | ||||
| $is_complete = false; | $is_complete = false; | ||||
| ▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | if (!$runnable) { | ||||
| $build->setBuildStatus(HarbormasterBuild::STATUS_FAILED); | $build->setBuildStatus(HarbormasterBuild::STATUS_FAILED); | ||||
| $build->save(); | $build->save(); | ||||
| return; | return; | ||||
| } | } | ||||
| foreach ($runnable as $runnable_step) { | foreach ($runnable as $runnable_step) { | ||||
| $target = HarbormasterBuildTarget::initializeNewBuildTarget( | $target = HarbormasterBuildTarget::initializeNewBuildTarget( | ||||
| $build, | $build, | ||||
| $step, | $runnable_step, | ||||
| $build->retrieveVariablesFromBuild()); | $build->retrieveVariablesFromBuild()); | ||||
| $target->save(); | $target->save(); | ||||
| $this->queueNewBuildTarget($target); | $this->queueNewBuildTarget($target); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||