Differential D19789 Diff 47256 src/infrastructure/daemon/workers/query/PhabricatorWorkerLeaseQuery.php
Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/daemon/workers/query/PhabricatorWorkerLeaseQuery.php
| Show First 20 Lines • Show All 203 Lines • ▼ Show 20 Lines | if ($this->skipLease) { | ||||
| // Reorder rows into the original phase order if this is a status query. | // Reorder rows into the original phase order if this is a status query. | ||||
| $tasks = array_select_keys($tasks, $task_ids); | $tasks = array_select_keys($tasks, $task_ids); | ||||
| } | } | ||||
| return $tasks; | return $tasks; | ||||
| } | } | ||||
| protected function buildCustomWhereClause( | protected function buildCustomWhereClause( | ||||
| AphrontDatabaseConnection $conn_w, | AphrontDatabaseConnection $conn, | ||||
| $phase) { | $phase) { | ||||
| $where = array(); | $where = array(); | ||||
| switch ($phase) { | switch ($phase) { | ||||
| case self::PHASE_LEASED: | case self::PHASE_LEASED: | ||||
| $where[] = 'leaseOwner IS NOT NULL'; | $where[] = qsprintf( | ||||
| $where[] = 'leaseExpires >= UNIX_TIMESTAMP()'; | $conn, | ||||
| 'leaseOwner IS NOT NULL'); | |||||
| $where[] = qsprintf( | |||||
| $conn, | |||||
| 'leaseExpires >= UNIX_TIMESTAMP()'); | |||||
| break; | break; | ||||
| case self::PHASE_UNLEASED: | case self::PHASE_UNLEASED: | ||||
| $where[] = 'leaseOwner IS NULL'; | $where[] = qsprintf( | ||||
| $conn, | |||||
| 'leaseOwner IS NULL'); | |||||
| break; | break; | ||||
| case self::PHASE_EXPIRED: | case self::PHASE_EXPIRED: | ||||
| $where[] = 'leaseExpires < UNIX_TIMESTAMP()'; | $where[] = qsprintf( | ||||
| $conn, | |||||
| 'leaseExpires < UNIX_TIMESTAMP()'); | |||||
| break; | break; | ||||
| default: | default: | ||||
| throw new Exception(pht("Unknown phase '%s'!", $phase)); | throw new Exception(pht("Unknown phase '%s'!", $phase)); | ||||
| } | } | ||||
| if ($this->ids !== null) { | if ($this->ids !== null) { | ||||
| $where[] = qsprintf($conn_w, 'id IN (%Ld)', $this->ids); | $where[] = qsprintf($conn, 'id IN (%Ld)', $this->ids); | ||||
| } | } | ||||
| if ($this->objectPHIDs !== null) { | if ($this->objectPHIDs !== null) { | ||||
| $where[] = qsprintf($conn_w, 'objectPHID IN (%Ls)', $this->objectPHIDs); | $where[] = qsprintf($conn, 'objectPHID IN (%Ls)', $this->objectPHIDs); | ||||
| } | } | ||||
| return $this->formatWhereClause($where); | return $this->formatWhereClause($conn, $where); | ||||
| } | } | ||||
| private function buildUpdateWhereClause( | private function buildUpdateWhereClause( | ||||
| AphrontDatabaseConnection $conn_w, | AphrontDatabaseConnection $conn, | ||||
| $phase, | $phase, | ||||
| array $rows) { | array $rows) { | ||||
| $where = array(); | $where = array(); | ||||
| // NOTE: This is basically working around the MySQL behavior that | // NOTE: This is basically working around the MySQL behavior that | ||||
| // `IN (NULL)` doesn't match NULL. | // `IN (NULL)` doesn't match NULL. | ||||
| switch ($phase) { | switch ($phase) { | ||||
| case self::PHASE_LEASED: | case self::PHASE_LEASED: | ||||
| throw new Exception( | throw new Exception( | ||||
| pht( | pht( | ||||
| 'Trying to lease tasks selected in the leased phase! This is '. | 'Trying to lease tasks selected in the leased phase! This is '. | ||||
| 'intended to be impossible.')); | 'intended to be impossible.')); | ||||
| case self::PHASE_UNLEASED: | case self::PHASE_UNLEASED: | ||||
| $where[] = qsprintf($conn_w, 'leaseOwner IS NULL'); | $where[] = qsprintf($conn, 'leaseOwner IS NULL'); | ||||
| $where[] = qsprintf($conn_w, 'id IN (%Ld)', ipull($rows, 'id')); | $where[] = qsprintf($conn, 'id IN (%Ld)', ipull($rows, 'id')); | ||||
| break; | break; | ||||
| case self::PHASE_EXPIRED: | case self::PHASE_EXPIRED: | ||||
| $in = array(); | $in = array(); | ||||
| foreach ($rows as $row) { | foreach ($rows as $row) { | ||||
| $in[] = qsprintf( | $in[] = qsprintf( | ||||
| $conn_w, | $conn, | ||||
| '(id = %d AND leaseOwner = %s)', | '(id = %d AND leaseOwner = %s)', | ||||
| $row['id'], | $row['id'], | ||||
| $row['leaseOwner']); | $row['leaseOwner']); | ||||
| } | } | ||||
| $where[] = qsprintf($conn_w, '(%Q)', implode(' OR ', $in)); | $where[] = qsprintf($conn, '%LO', $in); | ||||
| break; | break; | ||||
| default: | default: | ||||
| throw new Exception(pht('Unknown phase "%s"!', $phase)); | throw new Exception(pht('Unknown phase "%s"!', $phase)); | ||||
| } | } | ||||
| return $this->formatWhereClause($where); | return $this->formatWhereClause($conn, $where); | ||||
| } | } | ||||
| private function buildOrderClause(AphrontDatabaseConnection $conn_w, $phase) { | private function buildOrderClause(AphrontDatabaseConnection $conn_w, $phase) { | ||||
| switch ($phase) { | switch ($phase) { | ||||
| case self::PHASE_LEASED: | case self::PHASE_LEASED: | ||||
| // Ideally we'd probably order these by lease acquisition time, but | // Ideally we'd probably order these by lease acquisition time, but | ||||
| // we don't have that handy and this is a good approximation. | // we don't have that handy and this is a good approximation. | ||||
| return qsprintf($conn_w, 'ORDER BY priority ASC, id ASC'); | return qsprintf($conn_w, 'ORDER BY priority ASC, id ASC'); | ||||
| ▲ Show 20 Lines • Show All 51 Lines • Show Last 20 Lines | |||||