@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+64 -42
+4 -29
src/applications/harbormaster/engine/HarbormasterBuildEngine.php
··· 72 72 } 73 73 74 74 private function updateBuild(HarbormasterBuild $build) { 75 - 76 - $should_stop = false; 77 - $should_resume = false; 78 - $should_restart = false; 79 - foreach ($build->getUnprocessedCommands() as $command) { 80 - switch ($command->getCommand()) { 81 - case HarbormasterBuildCommand::COMMAND_STOP: 82 - $should_stop = true; 83 - $should_resume = false; 84 - break; 85 - case HarbormasterBuildCommand::COMMAND_RESUME: 86 - $should_resume = true; 87 - $should_stop = false; 88 - break; 89 - case HarbormasterBuildCommand::COMMAND_RESTART: 90 - $should_restart = true; 91 - $should_resume = true; 92 - $should_stop = false; 93 - break; 94 - } 95 - } 96 - 97 75 if (($build->getBuildStatus() == HarbormasterBuild::STATUS_PENDING) || 98 - ($should_restart)) { 76 + ($build->isRestarting())) { 99 77 $this->destroyBuildTargets($build); 100 78 $build->setBuildStatus(HarbormasterBuild::STATUS_BUILDING); 101 79 $build->save(); 102 80 } 103 81 104 - if ($should_resume) { 82 + if ($build->isResuming()) { 105 83 $build->setBuildStatus(HarbormasterBuild::STATUS_BUILDING); 106 84 $build->save(); 107 85 } 108 86 109 - if ($should_stop && !$build->isComplete()) { 87 + if ($build->isStopping() && !$build->isComplete()) { 110 88 $build->setBuildStatus(HarbormasterBuild::STATUS_STOPPED); 111 89 $build->save(); 112 90 } 113 91 114 - foreach ($build->getUnprocessedCommands() as $command) { 115 - $command->delete(); 116 - } 117 - $build->attachUnprocessedCommands(array()); 92 + $build->deleteUnprocessedCommands(); 118 93 119 94 if ($build->getBuildStatus() == HarbormasterBuild::STATUS_BUILDING) { 120 95 $this->updateBuildSteps($build);
+60 -13
src/applications/harbormaster/storage/build/HarbormasterBuild.php
··· 56 56 ->setBuildStatus(self::STATUS_INACTIVE); 57 57 } 58 58 59 + public function delete() { 60 + $this->openTransaction(); 61 + $this->deleteUnprocessedCommands(); 62 + $result = parent::delete(); 63 + $this->saveTransaction(); 64 + 65 + return $result; 66 + } 67 + 59 68 public function getConfiguration() { 60 69 return array( 61 70 self::CONFIG_AUX_PHID => true, ··· 212 221 /* -( Build Commands )----------------------------------------------------- */ 213 222 214 223 215 - public function getUnprocessedCommands() { 224 + private function getUnprocessedCommands() { 216 225 return $this->assertAttached($this->unprocessedCommands); 217 226 } 218 227 219 228 public function attachUnprocessedCommands(array $commands) { 220 229 $this->unprocessedCommands = $commands; 221 230 return $this; 222 - } 223 - 224 - public function hasWaitingCommand($command_name) { 225 - foreach ($this->getUnprocessedCommands() as $command_object) { 226 - if ($command_object->getCommand() == $command_name) { 227 - return true; 228 - } 229 - } 230 - return false; 231 231 } 232 232 233 233 public function canRestartBuild() { ··· 246 246 } 247 247 248 248 public function isStopping() { 249 - return $this->hasWaitingCommand(HarbormasterBuildCommand::COMMAND_STOP); 249 + $is_stopping = false; 250 + foreach ($this->getUnprocessedCommands() as $command_object) { 251 + $command = $command_object->getCommand(); 252 + switch ($command) { 253 + case HarbormasterBuildCommand::COMMAND_STOP: 254 + $is_stopping = true; 255 + break; 256 + case HarbormasterBuildCommand::COMMAND_RESUME: 257 + case HarbormasterBuildCommand::COMMAND_RESTART: 258 + $is_stopping = false; 259 + break; 260 + } 261 + } 262 + 263 + return $is_stopping; 250 264 } 251 265 252 266 public function isResuming() { 253 - return $this->hasWaitingCommand(HarbormasterBuildCommand::COMMAND_RESUME); 267 + $is_resuming = false; 268 + foreach ($this->getUnprocessedCommands() as $command_object) { 269 + $command = $command_object->getCommand(); 270 + switch ($command) { 271 + case HarbormasterBuildCommand::COMMAND_RESTART: 272 + case HarbormasterBuildCommand::COMMAND_RESUME: 273 + $is_resuming = true; 274 + break; 275 + case HarbormasterBuildCommand::COMMAND_STOP: 276 + $is_resuming = false; 277 + break; 278 + } 279 + } 280 + 281 + return $is_resuming; 254 282 } 255 283 256 284 public function isRestarting() { 257 - return $this->hasWaitingCommand(HarbormasterBuildCommand::COMMAND_RESTART); 285 + $is_restarting = false; 286 + foreach ($this->getUnprocessedCommands() as $command_object) { 287 + $command = $command_object->getCommand(); 288 + switch ($command) { 289 + case HarbormasterBuildCommand::COMMAND_RESTART: 290 + $is_restarting = true; 291 + break; 292 + } 293 + } 294 + 295 + return $is_restarting; 296 + } 297 + 298 + public function deleteUnprocessedCommands() { 299 + foreach ($this->getUnprocessedCommands() as $key => $command_object) { 300 + $command_object->delete(); 301 + unset($this->unprocessedCommands[$key]); 302 + } 303 + 304 + return $this; 258 305 } 259 306 260 307