mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-20 12:30: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',
|
'PhabricatorWorker' => 'infrastructure/daemon/workers/PhabricatorWorker.php',
|
||||||
'PhabricatorWorkerActiveTask' => 'infrastructure/daemon/workers/storage/PhabricatorWorkerActiveTask.php',
|
'PhabricatorWorkerActiveTask' => 'infrastructure/daemon/workers/storage/PhabricatorWorkerActiveTask.php',
|
||||||
'PhabricatorWorkerArchiveTask' => 'infrastructure/daemon/workers/storage/PhabricatorWorkerArchiveTask.php',
|
'PhabricatorWorkerArchiveTask' => 'infrastructure/daemon/workers/storage/PhabricatorWorkerArchiveTask.php',
|
||||||
|
'PhabricatorWorkerArchiveTaskQuery' => 'infrastructure/daemon/workers/query/PhabricatorWorkerArchiveTaskQuery.php',
|
||||||
'PhabricatorWorkerDAO' => 'infrastructure/daemon/workers/storage/PhabricatorWorkerDAO.php',
|
'PhabricatorWorkerDAO' => 'infrastructure/daemon/workers/storage/PhabricatorWorkerDAO.php',
|
||||||
'PhabricatorWorkerLeaseQuery' => 'infrastructure/daemon/workers/query/PhabricatorWorkerLeaseQuery.php',
|
'PhabricatorWorkerLeaseQuery' => 'infrastructure/daemon/workers/query/PhabricatorWorkerLeaseQuery.php',
|
||||||
'PhabricatorWorkerManagementCancelWorkflow' => 'infrastructure/daemon/workers/management/PhabricatorWorkerManagementCancelWorkflow.php',
|
'PhabricatorWorkerManagementCancelWorkflow' => 'infrastructure/daemon/workers/management/PhabricatorWorkerManagementCancelWorkflow.php',
|
||||||
|
@ -5750,6 +5751,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorWordPressAuthProvider' => 'PhabricatorOAuth2AuthProvider',
|
'PhabricatorWordPressAuthProvider' => 'PhabricatorOAuth2AuthProvider',
|
||||||
'PhabricatorWorkerActiveTask' => 'PhabricatorWorkerTask',
|
'PhabricatorWorkerActiveTask' => 'PhabricatorWorkerTask',
|
||||||
'PhabricatorWorkerArchiveTask' => 'PhabricatorWorkerTask',
|
'PhabricatorWorkerArchiveTask' => 'PhabricatorWorkerTask',
|
||||||
|
'PhabricatorWorkerArchiveTaskQuery' => 'PhabricatorQuery',
|
||||||
'PhabricatorWorkerDAO' => 'PhabricatorLiskDAO',
|
'PhabricatorWorkerDAO' => 'PhabricatorLiskDAO',
|
||||||
'PhabricatorWorkerLeaseQuery' => 'PhabricatorQuery',
|
'PhabricatorWorkerLeaseQuery' => 'PhabricatorQuery',
|
||||||
'PhabricatorWorkerManagementCancelWorkflow' => 'PhabricatorWorkerManagementWorkflow',
|
'PhabricatorWorkerManagementCancelWorkflow' => 'PhabricatorWorkerManagementWorkflow',
|
||||||
|
|
|
@ -14,9 +14,9 @@ final class PhabricatorDaemonConsoleController
|
||||||
// but we'd rather show that utilization is too high than too low.
|
// but we'd rather show that utilization is too high than too low.
|
||||||
$lease_overhead = 0.250;
|
$lease_overhead = 0.250;
|
||||||
|
|
||||||
$completed = id(new PhabricatorWorkerArchiveTask())->loadAllWhere(
|
$completed = id(new PhabricatorWorkerArchiveTaskQuery())
|
||||||
'dateModified > %d',
|
->withDateModifiedSince($window_start)
|
||||||
$window_start);
|
->execute();
|
||||||
|
|
||||||
$failed = id(new PhabricatorWorkerActiveTask())->loadAllWhere(
|
$failed = id(new PhabricatorWorkerActiveTask())->loadAllWhere(
|
||||||
'failureTime > %d',
|
'failureTime > %d',
|
||||||
|
|
|
@ -15,7 +15,10 @@ final class PhabricatorWorkerTaskDetailController
|
||||||
|
|
||||||
$task = id(new PhabricatorWorkerActiveTask())->load($this->id);
|
$task = id(new PhabricatorWorkerActiveTask())->load($this->id);
|
||||||
if (!$task) {
|
if (!$task) {
|
||||||
$task = id(new PhabricatorWorkerArchiveTask())->load($this->id);
|
$tasks = id(new PhabricatorWorkerArchiveTaskQuery())
|
||||||
|
->withIDs(array($this->id))
|
||||||
|
->execute();
|
||||||
|
$task = reset($tasks);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$task) {
|
if (!$task) {
|
||||||
|
|
|
@ -14,18 +14,16 @@ final class PhabricatorDaemonTaskGarbageCollector
|
||||||
$data_table = new PhabricatorWorkerTaskData();
|
$data_table = new PhabricatorWorkerTaskData();
|
||||||
$conn_w = $table->establishConnection('w');
|
$conn_w = $table->establishConnection('w');
|
||||||
|
|
||||||
$rows = queryfx_all(
|
$tasks = id(new PhabricatorWorkerArchiveTaskQuery())
|
||||||
$conn_w,
|
->withDateCreatedBefore(time() - $ttl)
|
||||||
'SELECT id, dataID FROM %T WHERE dateCreated < %d LIMIT 100',
|
->execute();
|
||||||
$table->getTableName(),
|
|
||||||
time() - $ttl);
|
|
||||||
|
|
||||||
if (!$rows) {
|
if (!$tasks) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$data_ids = array_filter(ipull($rows, 'dataID'));
|
$data_ids = array_filter(mpull($tasks, 'getDataID'));
|
||||||
$task_ids = ipull($rows, 'id');
|
$task_ids = mpull($tasks, 'getID');
|
||||||
|
|
||||||
$table->openTransaction();
|
$table->openTransaction();
|
||||||
if ($data_ids) {
|
if ($data_ids) {
|
||||||
|
|
|
@ -194,9 +194,8 @@ abstract class PhabricatorWorker {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$tasks = id(new PhabricatorWorkerArchiveTask())->loadAllWhere(
|
$tasks = id(new PhabricatorWorkerArchiveTaskQuery())
|
||||||
'id IN (%Ld)',
|
->withIDs($task_ids);
|
||||||
$task_ids);
|
|
||||||
|
|
||||||
foreach ($tasks as $task) {
|
foreach ($tasks as $task) {
|
||||||
if ($task->getResult() != PhabricatorWorkerArchiveTask::RESULT_SUCCESS) {
|
if ($task->getResult() != PhabricatorWorkerArchiveTask::RESULT_SUCCESS) {
|
||||||
|
|
|
@ -24,9 +24,9 @@ abstract class PhabricatorWorkerManagementWorkflow
|
||||||
$active_tasks = id(new PhabricatorWorkerActiveTask())->loadAllWhere(
|
$active_tasks = id(new PhabricatorWorkerActiveTask())->loadAllWhere(
|
||||||
'id IN (%Ls)',
|
'id IN (%Ls)',
|
||||||
$ids);
|
$ids);
|
||||||
$archive_tasks = id(new PhabricatorWorkerArchiveTask())->loadAllWhere(
|
$archive_tasks = id(new PhabricatorWorkerArchiveTaskQuery())
|
||||||
'id IN (%Ls)',
|
->withIDs($ids)
|
||||||
$ids);
|
->execute();
|
||||||
|
|
||||||
$tasks =
|
$tasks =
|
||||||
mpull($active_tasks, null, 'getID') +
|
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