Differential D11044 Diff 26524 src/infrastructure/daemon/workers/query/PhabricatorWorkerLeaseQuery.php
Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/daemon/workers/query/PhabricatorWorkerLeaseQuery.php
| <?php | <?php | ||||
| /** | /** | ||||
| * Select and lease tasks from the worker task queue. | * Select and lease tasks from the worker task queue. | ||||
| */ | */ | ||||
| final class PhabricatorWorkerLeaseQuery extends PhabricatorQuery { | final class PhabricatorWorkerLeaseQuery extends PhabricatorQuery { | ||||
| const PHASE_UNLEASED = 'unleased'; | const PHASE_UNLEASED = 'unleased'; | ||||
| const PHASE_EXPIRED = 'expired'; | const PHASE_EXPIRED = 'expired'; | ||||
| private $ids; | private $ids; | ||||
| private $objectPHIDs; | |||||
| private $limit; | private $limit; | ||||
| private $skipLease; | private $skipLease; | ||||
| public static function getDefaultWaitBeforeRetry() { | public static function getDefaultWaitBeforeRetry() { | ||||
| return phutil_units('5 minutes in seconds'); | return phutil_units('5 minutes in seconds'); | ||||
| } | } | ||||
| public static function getDefaultLeaseDuration() { | public static function getDefaultLeaseDuration() { | ||||
| Show All 14 Lines | public function setSkipLease($skip) { | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function withIDs(array $ids) { | public function withIDs(array $ids) { | ||||
| $this->ids = $ids; | $this->ids = $ids; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function withObjectPHIDs(array $phids) { | |||||
| $this->objectPHIDs = $phids; | |||||
| return $this; | |||||
| } | |||||
| public function setLimit($limit) { | public function setLimit($limit) { | ||||
| $this->limit = $limit; | $this->limit = $limit; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function execute() { | public function execute() { | ||||
| if (!$this->limit) { | if (!$this->limit) { | ||||
| throw new Exception('You must setLimit() when leasing tasks.'); | throw new Exception('You must setLimit() when leasing tasks.'); | ||||
| ▲ Show 20 Lines • Show All 120 Lines • ▼ Show 20 Lines | switch ($phase) { | ||||
| default: | default: | ||||
| throw new Exception("Unknown phase '{$phase}'!"); | throw new Exception("Unknown phase '{$phase}'!"); | ||||
| } | } | ||||
| if ($this->ids) { | if ($this->ids) { | ||||
| $where[] = qsprintf($conn_w, 'id IN (%Ld)', $this->ids); | $where[] = qsprintf($conn_w, 'id IN (%Ld)', $this->ids); | ||||
| } | } | ||||
| if ($this->objectPHIDs !== null) { | |||||
| $where[] = qsprintf($conn_w, 'objectPHID IN (%Ls)', $this->objectPHIDs); | |||||
epriestley: Should be `%Ls`. | |||||
Not Done Inline Actionstypo, will fix btrahan: typo, will fix | |||||
| } | |||||
| return $this->formatWhereClause($where); | return $this->formatWhereClause($where); | ||||
| } | } | ||||
| private function buildUpdateWhereClause( | private function buildUpdateWhereClause( | ||||
| AphrontDatabaseConnection $conn_w, | AphrontDatabaseConnection $conn_w, | ||||
| $phase, | $phase, | ||||
| array $rows) { | array $rows) { | ||||
| ▲ Show 20 Lines • Show All 81 Lines • Show Last 20 Lines | |||||
Should be %Ls.