private function buildPropertyListView(DrydockLease $lease, PhabricatorActionListView $actions) { $viewer = $this->getViewer(); $view = new PHUIPropertyListView(); $view->setActionList($actions); $view->addProperty(pht('Status'), DrydockLeaseStatus::getNameForStatus($lease->getStatus())); $view->addProperty(pht('Resource Type'), $lease->getResourceType()); $resource_phid = $lease->getResourcePHID(); if ($resource_phid) { $resource_display = $viewer->renderHandle($resource_phid); } else { $resource_display = phutil_tag('em', array(), pht('No Resource')); } $view->addProperty(pht('Resource'), $resource_display); $until = $lease->getUntil(); if ($until) { $until_display = phabricator_datetime($until, $viewer); } else { $until_display = phutil_tag('em', array(), pht('Never')); } $view->addProperty(pht('Expires'), $until_display); $attributes = $lease->getAttributes(); if ($attributes) { $view->addSectionHeader(pht('Attributes'), 'fa-list-ul'); foreach ($attributes as $key => $value) { $view->addProperty($key, $value); } } return $view; }
protected function yieldIfExpiringLease(DrydockLease $lease) { if (!$lease->canReceiveCommands()) { return; } $this->yieldIfExpiring($lease->getUntil()); }
private function updateLease(DrydockLease $lease) { if ($lease->getStatus() != DrydockLeaseStatus::STATUS_ACTIVE) { return; } $viewer = $this->getViewer(); $drydock_phid = id(new PhabricatorDrydockApplication())->getPHID(); // Check if the lease has expired. If it is, we're going to send it a // release command. This command will be handled immediately below, it // just generates a command log and improves consistency. $now = PhabricatorTime::getNow(); $expires = $lease->getUntil(); if ($expires && $expires <= $now) { $command = DrydockCommand::initializeNewCommand($viewer)->setTargetPHID($lease->getPHID())->setAuthorPHID($drydock_phid)->setCommand(DrydockCommand::COMMAND_RELEASE)->save(); } $commands = $this->loadCommands($lease->getPHID()); foreach ($commands as $command) { if ($lease->getStatus() != DrydockLeaseStatus::STATUS_ACTIVE) { // Leases can't receive commands before they activate or after they // release. break; } $this->processCommand($lease, $command); $command->setIsConsumed(true)->save(); } // If this is the task which will eventually release the lease after it // expires but it is still active, reschedule the task to run after the // lease expires. This can happen if the lease's expiration was pushed // forward. if ($lease->getStatus() == DrydockLeaseStatus::STATUS_ACTIVE) { if ($this->getTaskDataValue('isExpireTask') && $expires) { throw new PhabricatorWorkerYieldException($expires - $now); } } }