mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-19 05:12:41 +01:00
Allow worker tasks to be cancelled by classname
Summary: Ref T3554. Makes `bin/worker cancel --class <classname>` work (cancel all tasks with that type). This is useful in development if your queue is full of a bunch of gunk, and a need has occasionally arisen in production environments (usually "one option is cancel everything and move on"). Test Plan: Ran `bin/worker cancel` to cancel blocks of tasks by class name. Reviewers: chad Reviewed By: chad Maniphest Tasks: T3554 Differential Revision: https://secure.phabricator.com/D16267
This commit is contained in:
parent
c21be4849f
commit
c510c925cf
2 changed files with 52 additions and 13 deletions
|
@ -11,31 +11,57 @@ abstract class PhabricatorWorkerManagementWorkflow
|
|||
'repeat' => true,
|
||||
'help' => pht('Select one or more tasks by ID.'),
|
||||
),
|
||||
array(
|
||||
'name' => 'class',
|
||||
'param' => 'name',
|
||||
'help' => pht('Select all tasks of a given class.'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
protected function loadTasks(PhutilArgumentParser $args) {
|
||||
$ids = $args->getArg('id');
|
||||
if (!$ids) {
|
||||
$class = $args->getArg('class');
|
||||
|
||||
if (!$ids && !$class) {
|
||||
throw new PhutilArgumentUsageException(
|
||||
pht('Use --id to select tasks by ID.'));
|
||||
pht('Use --id or --class to select tasks.'));
|
||||
} if ($ids && $class) {
|
||||
throw new PhutilArgumentUsageException(
|
||||
pht('Use one of --id or --class to select tasks, but not both.'));
|
||||
}
|
||||
|
||||
$active_tasks = id(new PhabricatorWorkerActiveTask())->loadAllWhere(
|
||||
'id IN (%Ls)',
|
||||
$ids);
|
||||
$archive_tasks = id(new PhabricatorWorkerArchiveTaskQuery())
|
||||
->withIDs($ids)
|
||||
->execute();
|
||||
if ($ids) {
|
||||
$active_tasks = id(new PhabricatorWorkerActiveTask())->loadAllWhere(
|
||||
'id IN (%Ls)',
|
||||
$ids);
|
||||
$archive_tasks = id(new PhabricatorWorkerArchiveTaskQuery())
|
||||
->withIDs($ids)
|
||||
->execute();
|
||||
} else {
|
||||
$active_tasks = id(new PhabricatorWorkerActiveTask())->loadAllWhere(
|
||||
'taskClass IN (%Ls)',
|
||||
array($class));
|
||||
$archive_tasks = id(new PhabricatorWorkerArchiveTaskQuery())
|
||||
->withClassNames(array($class))
|
||||
->execute();
|
||||
}
|
||||
|
||||
$tasks =
|
||||
mpull($active_tasks, null, 'getID') +
|
||||
mpull($archive_tasks, null, 'getID');
|
||||
|
||||
foreach ($ids as $id) {
|
||||
if (empty($tasks[$id])) {
|
||||
if ($ids) {
|
||||
foreach ($ids as $id) {
|
||||
if (empty($tasks[$id])) {
|
||||
throw new PhutilArgumentUsageException(
|
||||
pht('No task exists with id "%s"!', $id));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!$tasks) {
|
||||
throw new PhutilArgumentUsageException(
|
||||
pht('No task exists with id "%s"!', $id));
|
||||
pht('No task exists with class "%s"!', $class));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ final class PhabricatorWorkerArchiveTaskQuery
|
|||
private $dateModifiedSince;
|
||||
private $dateCreatedBefore;
|
||||
private $objectPHIDs;
|
||||
private $classNames;
|
||||
private $limit;
|
||||
|
||||
public function withIDs(array $ids) {
|
||||
|
@ -29,6 +30,11 @@ final class PhabricatorWorkerArchiveTaskQuery
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function withClassNames(array $names) {
|
||||
$this->classNames = $names;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setLimit($limit) {
|
||||
$this->limit = $limit;
|
||||
return $this;
|
||||
|
@ -67,20 +73,27 @@ final class PhabricatorWorkerArchiveTaskQuery
|
|||
$this->objectPHIDs);
|
||||
}
|
||||
|
||||
if ($this->dateModifiedSince) {
|
||||
if ($this->dateModifiedSince !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'dateModified > %d',
|
||||
$this->dateModifiedSince);
|
||||
}
|
||||
|
||||
if ($this->dateCreatedBefore) {
|
||||
if ($this->dateCreatedBefore !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'dateCreated < %d',
|
||||
$this->dateCreatedBefore);
|
||||
}
|
||||
|
||||
if ($this->classNames !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'taskClass IN (%Ls)',
|
||||
$this->classNames);
|
||||
}
|
||||
|
||||
return $this->formatWhereClause($where);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue