1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-27 01:02:42 +01:00

Make HarbormasterBuild a better source of truth about restarting/resuming/stopping

Summary: Ref T1049. The logic in the BuildEngine is a little different from the logic on the Build itself. Make these more consistent, and make queued commands more private.

Test Plan: Restarted, stopped, and resumed a build.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T1049

Differential Revision: https://secure.phabricator.com/D7897
This commit is contained in:
epriestley 2014-01-06 14:11:59 -08:00
parent 1786093c6e
commit 6dc582f459
2 changed files with 64 additions and 42 deletions

View file

@ -72,49 +72,24 @@ final class HarbormasterBuildEngine extends Phobject {
} }
private function updateBuild(HarbormasterBuild $build) { private function updateBuild(HarbormasterBuild $build) {
$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) || if (($build->getBuildStatus() == HarbormasterBuild::STATUS_PENDING) ||
($should_restart)) { ($build->isRestarting())) {
$this->destroyBuildTargets($build); $this->destroyBuildTargets($build);
$build->setBuildStatus(HarbormasterBuild::STATUS_BUILDING); $build->setBuildStatus(HarbormasterBuild::STATUS_BUILDING);
$build->save(); $build->save();
} }
if ($should_resume) { if ($build->isResuming()) {
$build->setBuildStatus(HarbormasterBuild::STATUS_BUILDING); $build->setBuildStatus(HarbormasterBuild::STATUS_BUILDING);
$build->save(); $build->save();
} }
if ($should_stop && !$build->isComplete()) { if ($build->isStopping() && !$build->isComplete()) {
$build->setBuildStatus(HarbormasterBuild::STATUS_STOPPED); $build->setBuildStatus(HarbormasterBuild::STATUS_STOPPED);
$build->save(); $build->save();
} }
foreach ($build->getUnprocessedCommands() as $command) { $build->deleteUnprocessedCommands();
$command->delete();
}
$build->attachUnprocessedCommands(array());
if ($build->getBuildStatus() == HarbormasterBuild::STATUS_BUILDING) { if ($build->getBuildStatus() == HarbormasterBuild::STATUS_BUILDING) {
$this->updateBuildSteps($build); $this->updateBuildSteps($build);

View file

@ -56,6 +56,15 @@ final class HarbormasterBuild extends HarbormasterDAO
->setBuildStatus(self::STATUS_INACTIVE); ->setBuildStatus(self::STATUS_INACTIVE);
} }
public function delete() {
$this->openTransaction();
$this->deleteUnprocessedCommands();
$result = parent::delete();
$this->saveTransaction();
return $result;
}
public function getConfiguration() { public function getConfiguration() {
return array( return array(
self::CONFIG_AUX_PHID => true, self::CONFIG_AUX_PHID => true,
@ -212,7 +221,7 @@ final class HarbormasterBuild extends HarbormasterDAO
/* -( Build Commands )----------------------------------------------------- */ /* -( Build Commands )----------------------------------------------------- */
public function getUnprocessedCommands() { private function getUnprocessedCommands() {
return $this->assertAttached($this->unprocessedCommands); return $this->assertAttached($this->unprocessedCommands);
} }
@ -221,15 +230,6 @@ final class HarbormasterBuild extends HarbormasterDAO
return $this; return $this;
} }
public function hasWaitingCommand($command_name) {
foreach ($this->getUnprocessedCommands() as $command_object) {
if ($command_object->getCommand() == $command_name) {
return true;
}
}
return false;
}
public function canRestartBuild() { public function canRestartBuild() {
return !$this->isRestarting(); return !$this->isRestarting();
} }
@ -246,15 +246,62 @@ final class HarbormasterBuild extends HarbormasterDAO
} }
public function isStopping() { public function isStopping() {
return $this->hasWaitingCommand(HarbormasterBuildCommand::COMMAND_STOP); $is_stopping = false;
foreach ($this->getUnprocessedCommands() as $command_object) {
$command = $command_object->getCommand();
switch ($command) {
case HarbormasterBuildCommand::COMMAND_STOP:
$is_stopping = true;
break;
case HarbormasterBuildCommand::COMMAND_RESUME:
case HarbormasterBuildCommand::COMMAND_RESTART:
$is_stopping = false;
break;
}
}
return $is_stopping;
} }
public function isResuming() { public function isResuming() {
return $this->hasWaitingCommand(HarbormasterBuildCommand::COMMAND_RESUME); $is_resuming = false;
foreach ($this->getUnprocessedCommands() as $command_object) {
$command = $command_object->getCommand();
switch ($command) {
case HarbormasterBuildCommand::COMMAND_RESTART:
case HarbormasterBuildCommand::COMMAND_RESUME:
$is_resuming = true;
break;
case HarbormasterBuildCommand::COMMAND_STOP:
$is_resuming = false;
break;
}
}
return $is_resuming;
} }
public function isRestarting() { public function isRestarting() {
return $this->hasWaitingCommand(HarbormasterBuildCommand::COMMAND_RESTART); $is_restarting = false;
foreach ($this->getUnprocessedCommands() as $command_object) {
$command = $command_object->getCommand();
switch ($command) {
case HarbormasterBuildCommand::COMMAND_RESTART:
$is_restarting = true;
break;
}
}
return $is_restarting;
}
public function deleteUnprocessedCommands() {
foreach ($this->getUnprocessedCommands() as $key => $command_object) {
$command_object->delete();
unset($this->unprocessedCommands[$key]);
}
return $this;
} }