Changeset View
Changeset View
Standalone View
Standalone View
src/applications/drydock/worker/DrydockResourceUpdateWorker.php
Show All 14 Lines | protected function doWork() { | ||||
$this->updateResource($resource); | $this->updateResource($resource); | ||||
$lock->unlock(); | $lock->unlock(); | ||||
} | } | ||||
private function updateResource(DrydockResource $resource) { | private function updateResource(DrydockResource $resource) { | ||||
$commands = $this->loadCommands($resource->getPHID()); | $commands = $this->loadCommands($resource->getPHID()); | ||||
foreach ($commands as $command) { | foreach ($commands as $command) { | ||||
if ($resource->getStatus() != DrydockResourceStatus::STATUS_OPEN) { | if ($resource->getStatus() != DrydockResourceStatus::STATUS_ACTIVE) { | ||||
// Resources can't receive commands before they activate or after they | // Resources can't receive commands before they activate or after they | ||||
// release. | // release. | ||||
break; | break; | ||||
} | } | ||||
$this->processCommand($resource, $command); | $this->processCommand($resource, $command); | ||||
$command | $command | ||||
Show All 9 Lines | private function processCommand( | ||||
switch ($command->getCommand()) { | switch ($command->getCommand()) { | ||||
case DrydockCommand::COMMAND_RELEASE: | case DrydockCommand::COMMAND_RELEASE: | ||||
$this->releaseResource($resource); | $this->releaseResource($resource); | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
private function releaseResource(DrydockResource $resource) { | private function releaseResource(DrydockResource $resource) { | ||||
if ($resource->getStatus() != DrydockResourceStatus::STATUS_OPEN) { | if ($resource->getStatus() != DrydockResourceStatus::STATUS_ACTIVE) { | ||||
// If we had multiple release commands | // If we had multiple release commands | ||||
// This command is only meaningful to resources in the "Open" state. | // This command is only meaningful to resources in the "Open" state. | ||||
return; | return; | ||||
} | } | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
$drydock_phid = id(new PhabricatorDrydockApplication())->getPHID(); | $drydock_phid = id(new PhabricatorDrydockApplication())->getPHID(); | ||||
$resource->openTransaction(); | $resource->openTransaction(); | ||||
$resource | $resource | ||||
->setStatus(DrydockResourceStatus::STATUS_CLOSED) | ->setStatus(DrydockResourceStatus::STATUS_RELEASED) | ||||
->save(); | ->save(); | ||||
// TODO: Hold slot locks until destruction? | // TODO: Hold slot locks until destruction? | ||||
DrydockSlotLock::releaseLocks($resource->getPHID()); | DrydockSlotLock::releaseLocks($resource->getPHID()); | ||||
$resource->saveTransaction(); | $resource->saveTransaction(); | ||||
$statuses = array( | $statuses = array( | ||||
DrydockLeaseStatus::STATUS_PENDING, | DrydockLeaseStatus::STATUS_PENDING, | ||||
Show All 31 Lines |