@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.

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

+52 -13
+37 -11
src/infrastructure/daemon/workers/management/PhabricatorWorkerManagementWorkflow.php
··· 11 11 'repeat' => true, 12 12 'help' => pht('Select one or more tasks by ID.'), 13 13 ), 14 + array( 15 + 'name' => 'class', 16 + 'param' => 'name', 17 + 'help' => pht('Select all tasks of a given class.'), 18 + ), 14 19 ); 15 20 } 16 21 17 22 protected function loadTasks(PhutilArgumentParser $args) { 18 23 $ids = $args->getArg('id'); 19 - if (!$ids) { 24 + $class = $args->getArg('class'); 25 + 26 + if (!$ids && !$class) { 20 27 throw new PhutilArgumentUsageException( 21 - pht('Use --id to select tasks by ID.')); 28 + pht('Use --id or --class to select tasks.')); 29 + } if ($ids && $class) { 30 + throw new PhutilArgumentUsageException( 31 + pht('Use one of --id or --class to select tasks, but not both.')); 22 32 } 23 33 24 - $active_tasks = id(new PhabricatorWorkerActiveTask())->loadAllWhere( 25 - 'id IN (%Ls)', 26 - $ids); 27 - $archive_tasks = id(new PhabricatorWorkerArchiveTaskQuery()) 28 - ->withIDs($ids) 29 - ->execute(); 34 + if ($ids) { 35 + $active_tasks = id(new PhabricatorWorkerActiveTask())->loadAllWhere( 36 + 'id IN (%Ls)', 37 + $ids); 38 + $archive_tasks = id(new PhabricatorWorkerArchiveTaskQuery()) 39 + ->withIDs($ids) 40 + ->execute(); 41 + } else { 42 + $active_tasks = id(new PhabricatorWorkerActiveTask())->loadAllWhere( 43 + 'taskClass IN (%Ls)', 44 + array($class)); 45 + $archive_tasks = id(new PhabricatorWorkerArchiveTaskQuery()) 46 + ->withClassNames(array($class)) 47 + ->execute(); 48 + } 30 49 31 50 $tasks = 32 51 mpull($active_tasks, null, 'getID') + 33 52 mpull($archive_tasks, null, 'getID'); 34 53 35 - foreach ($ids as $id) { 36 - if (empty($tasks[$id])) { 54 + if ($ids) { 55 + foreach ($ids as $id) { 56 + if (empty($tasks[$id])) { 57 + throw new PhutilArgumentUsageException( 58 + pht('No task exists with id "%s"!', $id)); 59 + } 60 + } 61 + } else { 62 + if (!$tasks) { 37 63 throw new PhutilArgumentUsageException( 38 - pht('No task exists with id "%s"!', $id)); 64 + pht('No task exists with class "%s"!', $class)); 39 65 } 40 66 } 41 67
+15 -2
src/infrastructure/daemon/workers/query/PhabricatorWorkerArchiveTaskQuery.php
··· 7 7 private $dateModifiedSince; 8 8 private $dateCreatedBefore; 9 9 private $objectPHIDs; 10 + private $classNames; 10 11 private $limit; 11 12 12 13 public function withIDs(array $ids) { ··· 26 27 27 28 public function withObjectPHIDs(array $phids) { 28 29 $this->objectPHIDs = $phids; 30 + return $this; 31 + } 32 + 33 + public function withClassNames(array $names) { 34 + $this->classNames = $names; 29 35 return $this; 30 36 } 31 37 ··· 67 73 $this->objectPHIDs); 68 74 } 69 75 70 - if ($this->dateModifiedSince) { 76 + if ($this->dateModifiedSince !== null) { 71 77 $where[] = qsprintf( 72 78 $conn_r, 73 79 'dateModified > %d', 74 80 $this->dateModifiedSince); 75 81 } 76 82 77 - if ($this->dateCreatedBefore) { 83 + if ($this->dateCreatedBefore !== null) { 78 84 $where[] = qsprintf( 79 85 $conn_r, 80 86 'dateCreated < %d', 81 87 $this->dateCreatedBefore); 88 + } 89 + 90 + if ($this->classNames !== null) { 91 + $where[] = qsprintf( 92 + $conn_r, 93 + 'taskClass IN (%Ls)', 94 + $this->classNames); 82 95 } 83 96 84 97 return $this->formatWhereClause($where);