@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Daemons - introduce PhabricatorWorkerArchiveTaskQuery

Summary: Ref T5402. This cleans up some code and sets us up to use this sort of data more easily later.

Test Plan: viewed the daemon console from the web and the log of a specific archived daemon. both looked good. for other callsites looked really, really carefully.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin, epriestley

Maniphest Tasks: T5402

Differential Revision: https://secure.phabricator.com/D11042

+102 -18
+2
src/__phutil_library_map__.php
··· 2536 2536 'PhabricatorWorker' => 'infrastructure/daemon/workers/PhabricatorWorker.php', 2537 2537 'PhabricatorWorkerActiveTask' => 'infrastructure/daemon/workers/storage/PhabricatorWorkerActiveTask.php', 2538 2538 'PhabricatorWorkerArchiveTask' => 'infrastructure/daemon/workers/storage/PhabricatorWorkerArchiveTask.php', 2539 + 'PhabricatorWorkerArchiveTaskQuery' => 'infrastructure/daemon/workers/query/PhabricatorWorkerArchiveTaskQuery.php', 2539 2540 'PhabricatorWorkerDAO' => 'infrastructure/daemon/workers/storage/PhabricatorWorkerDAO.php', 2540 2541 'PhabricatorWorkerLeaseQuery' => 'infrastructure/daemon/workers/query/PhabricatorWorkerLeaseQuery.php', 2541 2542 'PhabricatorWorkerManagementCancelWorkflow' => 'infrastructure/daemon/workers/management/PhabricatorWorkerManagementCancelWorkflow.php', ··· 5750 5751 'PhabricatorWordPressAuthProvider' => 'PhabricatorOAuth2AuthProvider', 5751 5752 'PhabricatorWorkerActiveTask' => 'PhabricatorWorkerTask', 5752 5753 'PhabricatorWorkerArchiveTask' => 'PhabricatorWorkerTask', 5754 + 'PhabricatorWorkerArchiveTaskQuery' => 'PhabricatorQuery', 5753 5755 'PhabricatorWorkerDAO' => 'PhabricatorLiskDAO', 5754 5756 'PhabricatorWorkerLeaseQuery' => 'PhabricatorQuery', 5755 5757 'PhabricatorWorkerManagementCancelWorkflow' => 'PhabricatorWorkerManagementWorkflow',
+3 -3
src/applications/daemon/controller/PhabricatorDaemonConsoleController.php
··· 14 14 // but we'd rather show that utilization is too high than too low. 15 15 $lease_overhead = 0.250; 16 16 17 - $completed = id(new PhabricatorWorkerArchiveTask())->loadAllWhere( 18 - 'dateModified > %d', 19 - $window_start); 17 + $completed = id(new PhabricatorWorkerArchiveTaskQuery()) 18 + ->withDateModifiedSince($window_start) 19 + ->execute(); 20 20 21 21 $failed = id(new PhabricatorWorkerActiveTask())->loadAllWhere( 22 22 'failureTime > %d',
+4 -1
src/applications/daemon/controller/PhabricatorWorkerTaskDetailController.php
··· 15 15 16 16 $task = id(new PhabricatorWorkerActiveTask())->load($this->id); 17 17 if (!$task) { 18 - $task = id(new PhabricatorWorkerArchiveTask())->load($this->id); 18 + $tasks = id(new PhabricatorWorkerArchiveTaskQuery()) 19 + ->withIDs(array($this->id)) 20 + ->execute(); 21 + $task = reset($tasks); 19 22 } 20 23 21 24 if (!$task) {
+6 -8
src/applications/daemon/garbagecollector/PhabricatorDaemonTaskGarbageCollector.php
··· 14 14 $data_table = new PhabricatorWorkerTaskData(); 15 15 $conn_w = $table->establishConnection('w'); 16 16 17 - $rows = queryfx_all( 18 - $conn_w, 19 - 'SELECT id, dataID FROM %T WHERE dateCreated < %d LIMIT 100', 20 - $table->getTableName(), 21 - time() - $ttl); 17 + $tasks = id(new PhabricatorWorkerArchiveTaskQuery()) 18 + ->withDateCreatedBefore(time() - $ttl) 19 + ->execute(); 22 20 23 - if (!$rows) { 21 + if (!$tasks) { 24 22 return false; 25 23 } 26 24 27 - $data_ids = array_filter(ipull($rows, 'dataID')); 28 - $task_ids = ipull($rows, 'id'); 25 + $data_ids = array_filter(mpull($tasks, 'getDataID')); 26 + $task_ids = mpull($tasks, 'getID'); 29 27 30 28 $table->openTransaction(); 31 29 if ($data_ids) {
+2 -3
src/infrastructure/daemon/workers/PhabricatorWorker.php
··· 194 194 } 195 195 } 196 196 197 - $tasks = id(new PhabricatorWorkerArchiveTask())->loadAllWhere( 198 - 'id IN (%Ld)', 199 - $task_ids); 197 + $tasks = id(new PhabricatorWorkerArchiveTaskQuery()) 198 + ->withIDs($task_ids); 200 199 201 200 foreach ($tasks as $task) { 202 201 if ($task->getResult() != PhabricatorWorkerArchiveTask::RESULT_SUCCESS) {
+3 -3
src/infrastructure/daemon/workers/management/PhabricatorWorkerManagementWorkflow.php
··· 24 24 $active_tasks = id(new PhabricatorWorkerActiveTask())->loadAllWhere( 25 25 'id IN (%Ls)', 26 26 $ids); 27 - $archive_tasks = id(new PhabricatorWorkerArchiveTask())->loadAllWhere( 28 - 'id IN (%Ls)', 29 - $ids); 27 + $archive_tasks = id(new PhabricatorWorkerArchiveTaskQuery()) 28 + ->withIDs($ids) 29 + ->execute(); 30 30 31 31 $tasks = 32 32 mpull($active_tasks, null, 'getID') +
+82
src/infrastructure/daemon/workers/query/PhabricatorWorkerArchiveTaskQuery.php
··· 1 + <?php 2 + 3 + final class PhabricatorWorkerArchiveTaskQuery 4 + extends PhabricatorQuery { 5 + 6 + private $ids; 7 + private $dateModifiedSince; 8 + private $dateCreatedBefore; 9 + private $limit; 10 + 11 + public function withIDs(array $ids) { 12 + $this->ids = $ids; 13 + return $this; 14 + } 15 + 16 + public function withDateModifiedSince($timestamp) { 17 + $this->dateModifiedSince = $timestamp; 18 + return $this; 19 + } 20 + 21 + public function withDateCreatedBefore($timestamp) { 22 + $this->dateCreatedBefore = $timestamp; 23 + return $this; 24 + } 25 + 26 + public function setLimit($limit) { 27 + $this->limit = $limit; 28 + return $this; 29 + } 30 + 31 + public function execute() { 32 + 33 + $task_table = new PhabricatorWorkerArchiveTask(); 34 + 35 + $conn_r = $task_table->establishConnection('r'); 36 + 37 + $rows = queryfx_all( 38 + $conn_r, 39 + 'SELECT * FROM %T %Q %Q', 40 + $task_table->getTableName(), 41 + $this->buildWhereClause($conn_r), 42 + $this->buildLimitClause($conn_r)); 43 + 44 + return $task_table->loadAllFromArray($rows); 45 + } 46 + 47 + private function buildWhereClause(AphrontDatabaseConnection $conn_r) { 48 + $where = array(); 49 + 50 + if ($this->ids !== null) { 51 + $where[] = qsprintf( 52 + $conn_r, 53 + 'ids in (%Ld)', 54 + $this->ids); 55 + } 56 + 57 + if ($this->dateModifiedSince) { 58 + $where[] = qsprintf( 59 + $conn_r, 60 + 'dateModified > %d', 61 + $this->dateModifiedSince); 62 + } 63 + 64 + if ($this->dateCreatedBefore) { 65 + $where[] = qsprintf( 66 + $conn_r, 67 + 'dateCreated < %d', 68 + $this->dateCreatedBefore); 69 + } 70 + 71 + return $this->formatWhereClause($where); 72 + } 73 + 74 + private function buildLimitClause(AphrontDatabaseConnection $conn_r) { 75 + $clause = ''; 76 + if ($this->limit) { 77 + $clause = qsprintf($conn_r, 'LIMIT %d', $this->limit); 78 + } 79 + return $clause; 80 + } 81 + 82 + }