mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-24 06:20:56 +01:00
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
This commit is contained in:
parent
b3394c53d8
commit
a4474a4975
7 changed files with 102 additions and 18 deletions
|
@ -2536,6 +2536,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorWorker' => 'infrastructure/daemon/workers/PhabricatorWorker.php',
|
||||
'PhabricatorWorkerActiveTask' => 'infrastructure/daemon/workers/storage/PhabricatorWorkerActiveTask.php',
|
||||
'PhabricatorWorkerArchiveTask' => 'infrastructure/daemon/workers/storage/PhabricatorWorkerArchiveTask.php',
|
||||
'PhabricatorWorkerArchiveTaskQuery' => 'infrastructure/daemon/workers/query/PhabricatorWorkerArchiveTaskQuery.php',
|
||||
'PhabricatorWorkerDAO' => 'infrastructure/daemon/workers/storage/PhabricatorWorkerDAO.php',
|
||||
'PhabricatorWorkerLeaseQuery' => 'infrastructure/daemon/workers/query/PhabricatorWorkerLeaseQuery.php',
|
||||
'PhabricatorWorkerManagementCancelWorkflow' => 'infrastructure/daemon/workers/management/PhabricatorWorkerManagementCancelWorkflow.php',
|
||||
|
@ -5750,6 +5751,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorWordPressAuthProvider' => 'PhabricatorOAuth2AuthProvider',
|
||||
'PhabricatorWorkerActiveTask' => 'PhabricatorWorkerTask',
|
||||
'PhabricatorWorkerArchiveTask' => 'PhabricatorWorkerTask',
|
||||
'PhabricatorWorkerArchiveTaskQuery' => 'PhabricatorQuery',
|
||||
'PhabricatorWorkerDAO' => 'PhabricatorLiskDAO',
|
||||
'PhabricatorWorkerLeaseQuery' => 'PhabricatorQuery',
|
||||
'PhabricatorWorkerManagementCancelWorkflow' => 'PhabricatorWorkerManagementWorkflow',
|
||||
|
|
|
@ -14,9 +14,9 @@ final class PhabricatorDaemonConsoleController
|
|||
// but we'd rather show that utilization is too high than too low.
|
||||
$lease_overhead = 0.250;
|
||||
|
||||
$completed = id(new PhabricatorWorkerArchiveTask())->loadAllWhere(
|
||||
'dateModified > %d',
|
||||
$window_start);
|
||||
$completed = id(new PhabricatorWorkerArchiveTaskQuery())
|
||||
->withDateModifiedSince($window_start)
|
||||
->execute();
|
||||
|
||||
$failed = id(new PhabricatorWorkerActiveTask())->loadAllWhere(
|
||||
'failureTime > %d',
|
||||
|
|
|
@ -15,7 +15,10 @@ final class PhabricatorWorkerTaskDetailController
|
|||
|
||||
$task = id(new PhabricatorWorkerActiveTask())->load($this->id);
|
||||
if (!$task) {
|
||||
$task = id(new PhabricatorWorkerArchiveTask())->load($this->id);
|
||||
$tasks = id(new PhabricatorWorkerArchiveTaskQuery())
|
||||
->withIDs(array($this->id))
|
||||
->execute();
|
||||
$task = reset($tasks);
|
||||
}
|
||||
|
||||
if (!$task) {
|
||||
|
|
|
@ -14,18 +14,16 @@ final class PhabricatorDaemonTaskGarbageCollector
|
|||
$data_table = new PhabricatorWorkerTaskData();
|
||||
$conn_w = $table->establishConnection('w');
|
||||
|
||||
$rows = queryfx_all(
|
||||
$conn_w,
|
||||
'SELECT id, dataID FROM %T WHERE dateCreated < %d LIMIT 100',
|
||||
$table->getTableName(),
|
||||
time() - $ttl);
|
||||
$tasks = id(new PhabricatorWorkerArchiveTaskQuery())
|
||||
->withDateCreatedBefore(time() - $ttl)
|
||||
->execute();
|
||||
|
||||
if (!$rows) {
|
||||
if (!$tasks) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$data_ids = array_filter(ipull($rows, 'dataID'));
|
||||
$task_ids = ipull($rows, 'id');
|
||||
$data_ids = array_filter(mpull($tasks, 'getDataID'));
|
||||
$task_ids = mpull($tasks, 'getID');
|
||||
|
||||
$table->openTransaction();
|
||||
if ($data_ids) {
|
||||
|
|
|
@ -194,9 +194,8 @@ abstract class PhabricatorWorker {
|
|||
}
|
||||
}
|
||||
|
||||
$tasks = id(new PhabricatorWorkerArchiveTask())->loadAllWhere(
|
||||
'id IN (%Ld)',
|
||||
$task_ids);
|
||||
$tasks = id(new PhabricatorWorkerArchiveTaskQuery())
|
||||
->withIDs($task_ids);
|
||||
|
||||
foreach ($tasks as $task) {
|
||||
if ($task->getResult() != PhabricatorWorkerArchiveTask::RESULT_SUCCESS) {
|
||||
|
|
|
@ -24,9 +24,9 @@ abstract class PhabricatorWorkerManagementWorkflow
|
|||
$active_tasks = id(new PhabricatorWorkerActiveTask())->loadAllWhere(
|
||||
'id IN (%Ls)',
|
||||
$ids);
|
||||
$archive_tasks = id(new PhabricatorWorkerArchiveTask())->loadAllWhere(
|
||||
'id IN (%Ls)',
|
||||
$ids);
|
||||
$archive_tasks = id(new PhabricatorWorkerArchiveTaskQuery())
|
||||
->withIDs($ids)
|
||||
->execute();
|
||||
|
||||
$tasks =
|
||||
mpull($active_tasks, null, 'getID') +
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorWorkerArchiveTaskQuery
|
||||
extends PhabricatorQuery {
|
||||
|
||||
private $ids;
|
||||
private $dateModifiedSince;
|
||||
private $dateCreatedBefore;
|
||||
private $limit;
|
||||
|
||||
public function withIDs(array $ids) {
|
||||
$this->ids = $ids;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withDateModifiedSince($timestamp) {
|
||||
$this->dateModifiedSince = $timestamp;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withDateCreatedBefore($timestamp) {
|
||||
$this->dateCreatedBefore = $timestamp;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setLimit($limit) {
|
||||
$this->limit = $limit;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute() {
|
||||
|
||||
$task_table = new PhabricatorWorkerArchiveTask();
|
||||
|
||||
$conn_r = $task_table->establishConnection('r');
|
||||
|
||||
$rows = queryfx_all(
|
||||
$conn_r,
|
||||
'SELECT * FROM %T %Q %Q',
|
||||
$task_table->getTableName(),
|
||||
$this->buildWhereClause($conn_r),
|
||||
$this->buildLimitClause($conn_r));
|
||||
|
||||
return $task_table->loadAllFromArray($rows);
|
||||
}
|
||||
|
||||
private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
||||
$where = array();
|
||||
|
||||
if ($this->ids !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'ids in (%Ld)',
|
||||
$this->ids);
|
||||
}
|
||||
|
||||
if ($this->dateModifiedSince) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'dateModified > %d',
|
||||
$this->dateModifiedSince);
|
||||
}
|
||||
|
||||
if ($this->dateCreatedBefore) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'dateCreated < %d',
|
||||
$this->dateCreatedBefore);
|
||||
}
|
||||
|
||||
return $this->formatWhereClause($where);
|
||||
}
|
||||
|
||||
private function buildLimitClause(AphrontDatabaseConnection $conn_r) {
|
||||
$clause = '';
|
||||
if ($this->limit) {
|
||||
$clause = qsprintf($conn_r, 'LIMIT %d', $this->limit);
|
||||
}
|
||||
return $clause;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue