Changeset View
Changeset View
Standalone View
Standalone View
src/applications/harbormaster/storage/build/HarbormasterBuild.php
Show First 20 Lines • Show All 206 Lines • ▼ Show 20 Lines | public function isFailed() { | ||||
return $this->getBuildStatusObject()->isFailed(); | return $this->getBuildStatusObject()->isFailed(); | ||||
} | } | ||||
public function getURI() { | public function getURI() { | ||||
$id = $this->getID(); | $id = $this->getID(); | ||||
return "/harbormaster/build/{$id}/"; | return "/harbormaster/build/{$id}/"; | ||||
} | } | ||||
public function getBuildPendingStatusObject() { | |||||
// NOTE: If a build has multiple unprocessed messages, we'll ignore | |||||
// messages that are obsoleted by a later or stronger message. | |||||
// | |||||
// For example, if a build has both "pause" and "abort" messages in queue, | |||||
// we just ignore the "pause" message and perform an "abort", since pausing | |||||
// first wouldn't affect the final state, so we can just skip it. | |||||
// | |||||
// Likewise, if a build has both "restart" and "abort" messages, the most | |||||
// recent message is controlling: we'll take whichever action a command | |||||
// was most recently issued for. | |||||
$is_restarting = false; | |||||
$is_aborting = false; | |||||
$is_pausing = false; | |||||
$is_resuming = false; | |||||
foreach ($this->getUnprocessedMessages() as $message_object) { | |||||
$message_type = $message_object->getType(); | |||||
switch ($message_type) { | |||||
case HarbormasterBuildCommand::COMMAND_RESTART: | |||||
$is_restarting = true; | |||||
$is_aborting = false; | |||||
break; | |||||
case HarbormasterBuildCommand::COMMAND_ABORT: | |||||
$is_aborting = true; | |||||
$is_restarting = false; | |||||
break; | |||||
case HarbormasterBuildCommand::COMMAND_PAUSE: | |||||
$is_pausing = true; | |||||
$is_resuming = false; | |||||
break; | |||||
case HarbormasterBuildCommand::COMMAND_RESUME: | |||||
$is_resuming = true; | |||||
$is_pausing = false; | |||||
break; | |||||
} | |||||
} | |||||
$pending_status = null; | |||||
if ($is_restarting) { | |||||
$pending_status = HarbormasterBuildStatus::PENDING_RESTARTING; | |||||
} else if ($is_aborting) { | |||||
$pending_status = HarbormasterBuildStatus::PENDING_ABORTING; | |||||
} else if ($is_pausing) { | |||||
$pending_status = HarbormasterBuildStatus::PENDING_PAUSING; | |||||
} else if ($is_resuming) { | |||||
$pending_status = HarbormasterBuildStatus::PENDING_RESUMING; | |||||
} | |||||
if ($pending_status !== null) { | |||||
return HarbormasterBuildStatus::newBuildStatusObject($pending_status); | |||||
} | |||||
return $this->getBuildStatusObject(); | |||||
} | |||||
protected function getBuildStatusObject() { | protected function getBuildStatusObject() { | ||||
$status_key = $this->getBuildStatus(); | $status_key = $this->getBuildStatus(); | ||||
return HarbormasterBuildStatus::newBuildStatusObject($status_key); | return HarbormasterBuildStatus::newBuildStatusObject($status_key); | ||||
} | } | ||||
public function getObjectName() { | public function getObjectName() { | ||||
return pht('Build %d', $this->getID()); | return pht('Build %d', $this->getID()); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | /* -( Build Messages )----------------------------------------------------- */ | ||||
public function canPauseBuild() { | public function canPauseBuild() { | ||||
if ($this->isAutobuild()) { | if ($this->isAutobuild()) { | ||||
return false; | return false; | ||||
} | } | ||||
return !$this->isComplete() && | return !$this->isComplete() && | ||||
!$this->isPaused() && | !$this->isPaused() && | ||||
!$this->isPausing(); | !$this->isPausing() && | ||||
!$this->isRestarting() && | |||||
!$this->isAborting(); | |||||
} | } | ||||
public function canAbortBuild() { | public function canAbortBuild() { | ||||
if ($this->isAutobuild()) { | if ($this->isAutobuild()) { | ||||
return false; | return false; | ||||
} | } | ||||
return !$this->isComplete(); | return | ||||
!$this->isComplete() && | |||||
!$this->isAborting(); | |||||
} | } | ||||
public function canResumeBuild() { | public function canResumeBuild() { | ||||
if ($this->isAutobuild()) { | if ($this->isAutobuild()) { | ||||
return false; | return false; | ||||
} | } | ||||
return $this->isPaused() && | return | ||||
!$this->isResuming(); | $this->isPaused() && | ||||
!$this->isResuming() && | |||||
!$this->isRestarting() && | |||||
!$this->isAborting(); | |||||
} | } | ||||
public function isPausing() { | public function isPausing() { | ||||
$is_pausing = false; | return $this->getBuildPendingStatusObject()->isPausing(); | ||||
foreach ($this->getUnprocessedMessages() as $message_object) { | |||||
$message_type = $message_object->getType(); | |||||
switch ($message_type) { | |||||
case HarbormasterBuildCommand::COMMAND_PAUSE: | |||||
$is_pausing = true; | |||||
break; | |||||
case HarbormasterBuildCommand::COMMAND_RESUME: | |||||
case HarbormasterBuildCommand::COMMAND_RESTART: | |||||
$is_pausing = false; | |||||
break; | |||||
case HarbormasterBuildCommand::COMMAND_ABORT: | |||||
$is_pausing = true; | |||||
break; | |||||
} | |||||
} | |||||
return $is_pausing; | |||||
} | } | ||||
public function isResuming() { | public function isResuming() { | ||||
$is_resuming = false; | return $this->getBuildPendingStatusObject()->isResuming(); | ||||
foreach ($this->getUnprocessedMessages() as $message_object) { | |||||
$message_type = $message_object->getType(); | |||||
switch ($message_type) { | |||||
case HarbormasterBuildCommand::COMMAND_RESTART: | |||||
case HarbormasterBuildCommand::COMMAND_RESUME: | |||||
$is_resuming = true; | |||||
break; | |||||
case HarbormasterBuildCommand::COMMAND_PAUSE: | |||||
$is_resuming = false; | |||||
break; | |||||
case HarbormasterBuildCommand::COMMAND_ABORT: | |||||
$is_resuming = false; | |||||
break; | |||||
} | |||||
} | |||||
return $is_resuming; | |||||
} | } | ||||
public function isRestarting() { | public function isRestarting() { | ||||
$is_restarting = false; | return $this->getBuildPendingStatusObject()->isRestarting(); | ||||
foreach ($this->getUnprocessedMessages() as $message_object) { | |||||
$message_type = $message_object->getType(); | |||||
switch ($message_type) { | |||||
case HarbormasterBuildCommand::COMMAND_RESTART: | |||||
$is_restarting = true; | |||||
break; | |||||
} | |||||
} | |||||
return $is_restarting; | |||||
} | } | ||||
public function isAborting() { | public function isAborting() { | ||||
$is_aborting = false; | return $this->getBuildPendingStatusObject()->isAborting(); | ||||
foreach ($this->getUnprocessedMessages() as $message_object) { | |||||
$message_type = $message_object->getType(); | |||||
switch ($message_type) { | |||||
case HarbormasterBuildCommand::COMMAND_ABORT: | |||||
$is_aborting = true; | |||||
break; | |||||
} | |||||
} | |||||
return $is_aborting; | |||||
} | } | ||||
public function markUnprocessedMessagesAsProcessed() { | public function markUnprocessedMessagesAsProcessed() { | ||||
foreach ($this->getUnprocessedMessages() as $key => $message_object) { | foreach ($this->getUnprocessedMessages() as $key => $message_object) { | ||||
$message_object | $message_object | ||||
->setIsConsumed(1) | ->setIsConsumed(1) | ||||
->save(); | ->save(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 206 Lines • Show Last 20 Lines |