1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-23 21:18:19 +01:00
phorge-phorge/src/applications/drydock/worker/DrydockResourceWorker.php

46 lines
1.2 KiB
PHP
Raw Normal View History

<?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()'));
}
}
}