From 15e022d64870fc281887ab43b5da63ade05fd791 Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 22 Jan 2021 16:08:42 -0800 Subject: [PATCH] Support an "--active" flag for selecting active tasks Summary: Ref T13591. This is mostly a workaround for Big Sur not having pcntl/posix installed by default and the mess with M1 / Homebrew / SIP / Code Signing (see T13232) so I can't easily run actual daemons and need to fake them with `bin/worker execute --active`, but it's a reasonable flag on its own. Test Plan: - Ran `bin/worker execute --active` and `bin/worker cancel --active`. Maniphest Tasks: T13591 Differential Revision: https://secure.phabricator.com/D21517 --- .../PhabricatorWorkerManagementWorkflow.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/infrastructure/daemon/workers/management/PhabricatorWorkerManagementWorkflow.php b/src/infrastructure/daemon/workers/management/PhabricatorWorkerManagementWorkflow.php index 2f4ee2f4f5..113f3348d5 100644 --- a/src/infrastructure/daemon/workers/management/PhabricatorWorkerManagementWorkflow.php +++ b/src/infrastructure/daemon/workers/management/PhabricatorWorkerManagementWorkflow.php @@ -21,6 +21,10 @@ abstract class PhabricatorWorkerManagementWorkflow 'param' => 'int', 'help' => pht('Limit to tasks with at least this many failures.'), ), + array( + 'name' => 'active', + 'help' => pht('Select all active tasks.'), + ), ); } @@ -28,10 +32,13 @@ abstract class PhabricatorWorkerManagementWorkflow $ids = $args->getArg('id'); $class = $args->getArg('class'); $min_failures = $args->getArg('min-failure-count'); + $active = $args->getArg('active'); - if (!$ids && !$class && !$min_failures) { + if (!$ids && !$class && !$min_failures && !$active) { throw new PhutilArgumentUsageException( - pht('Use --id, --class, or --min-failure-count to select tasks.')); + pht( + 'Use "--id", "--class", "--active", and/or "--min-failure-count" '. + 'to select tasks.')); } $active_query = new PhabricatorWorkerActiveTaskQuery(); @@ -56,7 +63,13 @@ abstract class PhabricatorWorkerManagementWorkflow } $active_tasks = $active_query->execute(); - $archive_tasks = $archive_query->execute(); + + if ($active) { + $archive_tasks = array(); + } else { + $archive_tasks = $archive_query->execute(); + } + $tasks = mpull($active_tasks, null, 'getID') + mpull($archive_tasks, null, 'getID');