mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-23 21:18:19 +01:00
f1119ffcf5
Summary: Ref T9253. For resources and leases that need to do something which takes a lot of time or requires waiting, allow them to allocate/acquire first and then activate later. When we allocate a resource or acquire a lease, the blueprint can either activate it immediately (if all the work can happen quickly/inline) or activate it later. If the blueprint activates it later, we queue a worker to handle activating it. Rebuild the "working copy" blueprint to work with this model: it allocates/acquires and activates in a separate step, once it is able to acquire a host. Test Plan: With some power of imagination, brought up a bunch of working copies with `bin/drydock lease --type working-copy ...` Reviewers: hach-que, chad Reviewed By: hach-que, chad Maniphest Tasks: T9253 Differential Revision: https://secure.phabricator.com/D14127
45 lines
1.2 KiB
PHP
45 lines
1.2 KiB
PHP
<?php
|
|
|
|
final class DrydockResourceWorker extends DrydockWorker {
|
|
|
|
protected function doWork() {
|
|
$resource_phid = $this->getTaskDataValue('resourcePHID');
|
|
$resource = $this->loadResource($resource_phid);
|
|
|
|
$this->activateResource($resource);
|
|
}
|
|
|
|
|
|
private function activateResource(DrydockResource $resource) {
|
|
$resource_status = $resource->getStatus();
|
|
|
|
if ($resource_status != DrydockResourceStatus::STATUS_PENDING) {
|
|
throw new PhabricatorWorkerPermanentFailureException(
|
|
pht(
|
|
'Trying to activate resource from wrong status ("%s").',
|
|
$resource_status));
|
|
}
|
|
|
|
$blueprint = $resource->getBlueprint();
|
|
$blueprint->activateResource($resource);
|
|
$this->validateActivatedResource($blueprint, $resource);
|
|
}
|
|
|
|
|
|
private function validateActivatedResource(
|
|
DrydockBlueprint $blueprint,
|
|
DrydockResource $resource) {
|
|
|
|
if (!$resource->isActivatedResource()) {
|
|
throw new Exception(
|
|
pht(
|
|
'Blueprint "%s" (of type "%s") is not properly implemented: %s '.
|
|
'must actually allocate the resource it returns.',
|
|
$blueprint->getBlueprintName(),
|
|
$blueprint->getClassName(),
|
|
'allocateResource()'));
|
|
}
|
|
|
|
}
|
|
|
|
}
|