Page MenuHomePhabricator

D14147.id.diff
No OneTemporary

D14147.id.diff

diff --git a/resources/sql/autopatches/20150923.drydock.taskid.1.sql b/resources/sql/autopatches/20150923.drydock.taskid.1.sql
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20150923.drydock.taskid.1.sql
@@ -0,0 +1,2 @@
+ALTER TABLE {$NAMESPACE}_drydock.drydock_lease
+ DROP taskID;
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -812,7 +812,6 @@
'DrydockBlueprintListController' => 'applications/drydock/controller/DrydockBlueprintListController.php',
'DrydockBlueprintPHIDType' => 'applications/drydock/phid/DrydockBlueprintPHIDType.php',
'DrydockBlueprintQuery' => 'applications/drydock/query/DrydockBlueprintQuery.php',
- 'DrydockBlueprintScopeGuard' => 'applications/drydock/util/DrydockBlueprintScopeGuard.php',
'DrydockBlueprintSearchEngine' => 'applications/drydock/query/DrydockBlueprintSearchEngine.php',
'DrydockBlueprintTransaction' => 'applications/drydock/storage/DrydockBlueprintTransaction.php',
'DrydockBlueprintTransactionQuery' => 'applications/drydock/query/DrydockBlueprintTransactionQuery.php',
@@ -4538,7 +4537,6 @@
'DrydockBlueprintListController' => 'DrydockBlueprintController',
'DrydockBlueprintPHIDType' => 'PhabricatorPHIDType',
'DrydockBlueprintQuery' => 'DrydockQuery',
- 'DrydockBlueprintScopeGuard' => 'Phobject',
'DrydockBlueprintSearchEngine' => 'PhabricatorApplicationSearchEngine',
'DrydockBlueprintTransaction' => 'PhabricatorApplicationTransaction',
'DrydockBlueprintTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
diff --git a/src/applications/drydock/blueprint/DrydockBlueprintImplementation.php b/src/applications/drydock/blueprint/DrydockBlueprintImplementation.php
--- a/src/applications/drydock/blueprint/DrydockBlueprintImplementation.php
+++ b/src/applications/drydock/blueprint/DrydockBlueprintImplementation.php
@@ -8,9 +8,6 @@
*/
abstract class DrydockBlueprintImplementation extends Phobject {
- private $activeResource;
- private $activeLease;
-
abstract public function getType();
abstract public function isEnabled();
@@ -265,10 +262,7 @@
* @task log
*/
protected function log($message) {
- self::writeLog(
- $this->activeResource,
- $this->activeLease,
- $message);
+ self::writeLog(null, null, $message);
}
@@ -320,13 +314,6 @@
// Pre-allocate the resource PHID.
$resource->setPHID($resource->generatePHID());
- $this->activeResource = $resource;
-
- $this->log(
- pht(
- "Blueprint '%s': Created New Template",
- get_class($this)));
-
return $resource;
}
@@ -349,24 +336,4 @@
}
}
- private function pushActiveScope(
- DrydockResource $resource = null,
- DrydockLease $lease = null) {
-
- if (($this->activeResource !== null) ||
- ($this->activeLease !== null)) {
- throw new Exception(pht('There is already an active resource or lease!'));
- }
-
- $this->activeResource = $resource;
- $this->activeLease = $lease;
-
- return new DrydockBlueprintScopeGuard($this);
- }
-
- public function popActiveScope() {
- $this->activeResource = null;
- $this->activeLease = null;
- }
-
}
diff --git a/src/applications/drydock/storage/DrydockLease.php b/src/applications/drydock/storage/DrydockLease.php
--- a/src/applications/drydock/storage/DrydockLease.php
+++ b/src/applications/drydock/storage/DrydockLease.php
@@ -9,7 +9,6 @@
protected $ownerPHID;
protected $attributes = array();
protected $status = DrydockLeaseStatus::STATUS_PENDING;
- protected $taskID;
private $resource = self::ATTACHABLE;
private $releaseOnDestruction;
@@ -64,7 +63,6 @@
'status' => 'uint32',
'until' => 'epoch?',
'resourceType' => 'text128',
- 'taskID' => 'id?',
'ownerPHID' => 'phid?',
'resourceID' => 'id?',
),
@@ -108,20 +106,15 @@
return ($this->resource !== null);
}
- public function loadResource() {
- return id(new DrydockResource())->loadOneWhere(
- 'id = %d',
- $this->getResourceID());
- }
-
public function queueForActivation() {
if ($this->getID()) {
throw new Exception(
pht('Only new leases may be queued for activation!'));
}
- $this->setStatus(DrydockLeaseStatus::STATUS_PENDING);
- $this->save();
+ $this
+ ->setStatus(DrydockLeaseStatus::STATUS_PENDING)
+ ->save();
$task = PhabricatorWorker::scheduleTask(
'DrydockAllocatorWorker',
@@ -132,14 +125,6 @@
'objectPHID' => $this->getPHID(),
));
- // NOTE: Scheduling the task might execute it in-process, if we're running
- // from a CLI script. Reload the lease to make sure we have the most
- // up-to-date information. Normally, this has no effect.
- $this->reload();
-
- $this->setTaskID($task->getID());
- $this->save();
-
return $this;
}
@@ -161,54 +146,36 @@
}
}
- public static function waitForLeases(array $leases) {
- assert_instances_of($leases, __CLASS__);
-
- $task_ids = array_filter(mpull($leases, 'getTaskID'));
-
- PhabricatorWorker::waitForTasks($task_ids);
-
- $unresolved = $leases;
+ public function waitUntilActive() {
while (true) {
- foreach ($unresolved as $key => $lease) {
- $lease->reload();
- switch ($lease->getStatus()) {
- case DrydockLeaseStatus::STATUS_ACTIVE:
- unset($unresolved[$key]);
- break;
- case DrydockLeaseStatus::STATUS_RELEASED:
- throw new Exception(pht('Lease has already been released!'));
- case DrydockLeaseStatus::STATUS_EXPIRED:
- throw new Exception(pht('Lease has already expired!'));
- case DrydockLeaseStatus::STATUS_BROKEN:
- throw new Exception(pht('Lease has been broken!'));
- case DrydockLeaseStatus::STATUS_PENDING:
- case DrydockLeaseStatus::STATUS_ACQUIRED:
- break;
- default:
- throw new Exception(pht('Unknown status??'));
- }
+ $lease = $this->reload();
+ if (!$lease) {
+ throw new Exception(pht('Failed to reload lease.'));
}
- if ($unresolved) {
- sleep(1);
- } else {
- break;
+ $status = $lease->getStatus();
+
+ switch ($status) {
+ case DrydockLeaseStatus::STATUS_ACTIVE:
+ return;
+ case DrydockLeaseStatus::STATUS_RELEASED:
+ throw new Exception(pht('Lease has already been released!'));
+ case DrydockLeaseStatus::STATUS_EXPIRED:
+ throw new Exception(pht('Lease has already expired!'));
+ case DrydockLeaseStatus::STATUS_BROKEN:
+ throw new Exception(pht('Lease has been broken!'));
+ case DrydockLeaseStatus::STATUS_PENDING:
+ case DrydockLeaseStatus::STATUS_ACQUIRED:
+ break;
+ default:
+ throw new Exception(
+ pht(
+ 'Lease has unknown status "%s".',
+ $status));
}
- }
-
- foreach ($leases as $lease) {
- $lease->attachResource($lease->loadResource());
- }
- }
- public function waitUntilActive() {
- if (!$this->getID()) {
- $this->queueForActivation();
+ sleep(1);
}
-
- self::waitForLeases(array($this));
- return $this;
}
public function setActivateWhenAcquired($activate) {
diff --git a/src/applications/drydock/util/DrydockBlueprintScopeGuard.php b/src/applications/drydock/util/DrydockBlueprintScopeGuard.php
deleted file mode 100644
--- a/src/applications/drydock/util/DrydockBlueprintScopeGuard.php
+++ /dev/null
@@ -1,15 +0,0 @@
-<?php
-
-final class DrydockBlueprintScopeGuard extends Phobject {
-
- private $blueprint;
-
- public function __construct(DrydockBlueprintImplementation $blueprint) {
- $this->blueprint = $blueprint;
- }
-
- public function __destruct() {
- $this->blueprint->popActiveScope();
- }
-
-}
diff --git a/src/infrastructure/daemon/workers/PhabricatorWorker.php b/src/infrastructure/daemon/workers/PhabricatorWorker.php
--- a/src/infrastructure/daemon/workers/PhabricatorWorker.php
+++ b/src/infrastructure/daemon/workers/PhabricatorWorker.php
@@ -157,51 +157,6 @@
}
- /**
- * Wait for tasks to complete.
- *
- * @param list<int> List of queued task IDs to wait for.
- * @return void
- */
- final public static function waitForTasks(array $task_ids) {
- if (!$task_ids) {
- return;
- }
-
- $task_table = new PhabricatorWorkerActiveTask();
-
- $waiting = array_fuse($task_ids);
- while ($waiting) {
- $conn_w = $task_table->establishConnection('w');
-
- // Check if any of the tasks we're waiting on are still queued. If they
- // are not, we're done waiting.
- $row = queryfx_one(
- $conn_w,
- 'SELECT COUNT(*) N FROM %T WHERE id IN (%Ld)',
- $task_table->getTableName(),
- $waiting);
- if (!$row['N']) {
- // Nothing is queued anymore. Stop waiting.
- break;
- }
-
- // We were not successful in leasing anything. Sleep for a bit and
- // see if we have better luck later.
- sleep(1);
- }
-
- $tasks = id(new PhabricatorWorkerArchiveTaskQuery())
- ->withIDs($task_ids)
- ->execute();
-
- foreach ($tasks as $task) {
- if ($task->getResult() != PhabricatorWorkerArchiveTask::RESULT_SUCCESS) {
- throw new Exception(pht('Task %d failed!', $task->getID()));
- }
- }
- }
-
public function renderForDisplay(PhabricatorUser $viewer) {
return null;
}

File Metadata

Mime Type
text/plain
Expires
Oct 18 2024, 5:44 AM (4 w, 3 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6725225
Default Alt Text
D14147.id.diff (9 KB)

Event Timeline