diff --git a/src/infrastructure/daemon/workers/management/PhabricatorWorkerManagementWorkflow.php b/src/infrastructure/daemon/workers/management/PhabricatorWorkerManagementWorkflow.php --- a/src/infrastructure/daemon/workers/management/PhabricatorWorkerManagementWorkflow.php +++ b/src/infrastructure/daemon/workers/management/PhabricatorWorkerManagementWorkflow.php @@ -11,31 +11,57 @@ '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)); } } diff --git a/src/infrastructure/daemon/workers/query/PhabricatorWorkerArchiveTaskQuery.php b/src/infrastructure/daemon/workers/query/PhabricatorWorkerArchiveTaskQuery.php --- a/src/infrastructure/daemon/workers/query/PhabricatorWorkerArchiveTaskQuery.php +++ b/src/infrastructure/daemon/workers/query/PhabricatorWorkerArchiveTaskQuery.php @@ -7,6 +7,7 @@ private $dateModifiedSince; private $dateCreatedBefore; private $objectPHIDs; + private $classNames; private $limit; public function withIDs(array $ids) { @@ -29,6 +30,11 @@ 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 @@ $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); }