private function releaseLease(DrydockLease $lease)
 {
     $lease->openTransaction();
     $lease->setStatus(DrydockLeaseStatus::STATUS_RELEASED)->save();
     // TODO: Hold slot locks until destruction?
     DrydockSlotLock::releaseLocks($lease->getPHID());
     $lease->saveTransaction();
     PhabricatorWorker::scheduleTask('DrydockLeaseDestroyWorker', array('leasePHID' => $lease->getPHID()), array('objectPHID' => $lease->getPHID()));
     $resource = $lease->getResource();
     $blueprint = $resource->getBlueprint();
     $blueprint->didReleaseLease($resource, $lease);
 }
 private function destroyLease(DrydockLease $lease)
 {
     $status = $lease->getStatus();
     switch ($status) {
         case DrydockLeaseStatus::STATUS_RELEASED:
         case DrydockLeaseStatus::STATUS_BROKEN:
             break;
         default:
             throw new PhabricatorWorkerPermanentFailureException(pht('Unable to destroy lease ("%s"), lease has the wrong ' . 'status ("%s").', $lease->getPHID(), $status));
     }
     $resource = $lease->getResource();
     $blueprint = $resource->getBlueprint();
     $blueprint->destroyLease($resource, $lease);
     $lease->setStatus(DrydockLeaseStatus::STATUS_DESTROYED)->save();
 }
 /**
  * @task break
  */
 protected function breakLease(DrydockLease $lease, Exception $ex)
 {
     switch ($lease->getStatus()) {
         case DrydockLeaseStatus::STATUS_BROKEN:
         case DrydockLeaseStatus::STATUS_RELEASED:
         case DrydockLeaseStatus::STATUS_DESTROYED:
             throw new PhutilProxyException(pht('Unexpected failure while destroying lease ("%s").', $lease->getPHID()), $ex);
     }
     $lease->setStatus(DrydockLeaseStatus::STATUS_BROKEN)->save();
     $lease->logEvent(DrydockLeaseActivationFailureLogType::LOGCONST, array('class' => get_class($ex), 'message' => $ex->getMessage()));
     $lease->awakenTasks();
     $this->queueTask(__CLASS__, array('leasePHID' => $lease->getPHID()), array('objectPHID' => $lease->getPHID()));
     throw new PhabricatorWorkerPermanentFailureException(pht('Permanent failure while activating lease ("%s"): %s', $lease->getPHID(), $ex->getMessage()));
 }
 protected function requireActiveLease(DrydockLease $lease)
 {
     $lease_status = $lease->getStatus();
     switch ($lease_status) {
         case DrydockLeaseStatus::STATUS_PENDING:
         case DrydockLeaseStatus::STATUS_ACQUIRED:
             throw new PhabricatorWorkerYieldException(15);
         case DrydockLeaseStatus::STATUS_ACTIVE:
             return;
         default:
             throw new Exception(pht('Lease ("%s") is in bad state ("%s"), expected "%s".', $lease->getPHID(), $lease_status, DrydockLeaseStatus::STATUS_ACTIVE));
     }
 }
Ejemplo n.º 5
0
 protected function reclaimResource(DrydockResource $resource, DrydockLease $lease)
 {
     $viewer = $this->getViewer();
     $command = DrydockCommand::initializeNewCommand($viewer)->setTargetPHID($resource->getPHID())->setAuthorPHID($lease->getPHID())->setCommand(DrydockCommand::COMMAND_RECLAIM)->save();
     $resource->scheduleUpdate();
     return $this;
 }