Differential D16267 Diff 39139 src/infrastructure/daemon/workers/management/PhabricatorWorkerManagementWorkflow.php
Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/daemon/workers/management/PhabricatorWorkerManagementWorkflow.php
<?php | <?php | ||||
abstract class PhabricatorWorkerManagementWorkflow | abstract class PhabricatorWorkerManagementWorkflow | ||||
extends PhabricatorManagementWorkflow { | extends PhabricatorManagementWorkflow { | ||||
protected function getTaskSelectionArguments() { | protected function getTaskSelectionArguments() { | ||||
return array( | return array( | ||||
array( | array( | ||||
'name' => 'id', | 'name' => 'id', | ||||
'param' => 'id', | 'param' => 'id', | ||||
'repeat' => true, | 'repeat' => true, | ||||
'help' => pht('Select one or more tasks by ID.'), | '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) { | protected function loadTasks(PhutilArgumentParser $args) { | ||||
$ids = $args->getArg('id'); | $ids = $args->getArg('id'); | ||||
if (!$ids) { | $class = $args->getArg('class'); | ||||
if (!$ids && !$class) { | |||||
throw new PhutilArgumentUsageException( | 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.')); | |||||
} | } | ||||
if ($ids) { | |||||
$active_tasks = id(new PhabricatorWorkerActiveTask())->loadAllWhere( | $active_tasks = id(new PhabricatorWorkerActiveTask())->loadAllWhere( | ||||
'id IN (%Ls)', | 'id IN (%Ls)', | ||||
$ids); | $ids); | ||||
$archive_tasks = id(new PhabricatorWorkerArchiveTaskQuery()) | $archive_tasks = id(new PhabricatorWorkerArchiveTaskQuery()) | ||||
->withIDs($ids) | ->withIDs($ids) | ||||
->execute(); | ->execute(); | ||||
} else { | |||||
$active_tasks = id(new PhabricatorWorkerActiveTask())->loadAllWhere( | |||||
'taskClass IN (%Ls)', | |||||
array($class)); | |||||
$archive_tasks = id(new PhabricatorWorkerArchiveTaskQuery()) | |||||
->withClassNames(array($class)) | |||||
->execute(); | |||||
} | |||||
$tasks = | $tasks = | ||||
mpull($active_tasks, null, 'getID') + | mpull($active_tasks, null, 'getID') + | ||||
mpull($archive_tasks, null, 'getID'); | mpull($archive_tasks, null, 'getID'); | ||||
if ($ids) { | |||||
foreach ($ids as $id) { | foreach ($ids as $id) { | ||||
if (empty($tasks[$id])) { | if (empty($tasks[$id])) { | ||||
throw new PhutilArgumentUsageException( | throw new PhutilArgumentUsageException( | ||||
pht('No task exists with id "%s"!', $id)); | pht('No task exists with id "%s"!', $id)); | ||||
} | } | ||||
} | } | ||||
} else { | |||||
if (!$tasks) { | |||||
throw new PhutilArgumentUsageException( | |||||
pht('No task exists with class "%s"!', $class)); | |||||
} | |||||
} | |||||
// When we lock tasks properly, this gets populated as a side effect. Just | // When we lock tasks properly, this gets populated as a side effect. Just | ||||
// fake it when doing manual CLI stuff. This makes sure CLI yields have | // fake it when doing manual CLI stuff. This makes sure CLI yields have | ||||
// their expires times set properly. | // their expires times set properly. | ||||
foreach ($tasks as $task) { | foreach ($tasks as $task) { | ||||
if ($task instanceof PhabricatorWorkerActiveTask) { | if ($task instanceof PhabricatorWorkerActiveTask) { | ||||
$task->setServerTime(PhabricatorTime::getNow()); | $task->setServerTime(PhabricatorTime::getNow()); | ||||
} | } | ||||
Show All 10 Lines |