mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-11 07:11:04 +01:00
Give "bin/worker" flags to repeat and retry tasks
Summary: See PHI1063. See PHI1114. Ref T13253. Currently, you can't `bin/worker execute` an archived task and can't `bin/worker retry` a successful task. Although it's good not to do these things by default (particularly, retrying a successful task will double its effects), there are plenty of cases where you want to re-run something for testing/development/debugging and don't care that the effect will repeat (you're in a dev environment, the effect doesn't matter, etc). Test Plan: Ran `bin/worker execute/retry` against archived/successful tasks. Got prompted to add more flags, then got re-execution. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13253 Differential Revision: https://secure.phabricator.com/D20246
This commit is contained in:
parent
e15fff00a6
commit
9b0b50fbf4
2 changed files with 67 additions and 14 deletions
|
@ -11,23 +11,64 @@ final class PhabricatorWorkerManagementExecuteWorkflow
|
||||||
pht(
|
pht(
|
||||||
'Execute a task explicitly. This command ignores leases, is '.
|
'Execute a task explicitly. This command ignores leases, is '.
|
||||||
'dangerous, and may cause work to be performed twice.'))
|
'dangerous, and may cause work to be performed twice.'))
|
||||||
->setArguments($this->getTaskSelectionArguments());
|
->setArguments(
|
||||||
|
array_merge(
|
||||||
|
array(
|
||||||
|
array(
|
||||||
|
'name' => 'retry',
|
||||||
|
'help' => pht('Retry archived tasks.'),
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'name' => 'repeat',
|
||||||
|
'help' => pht('Repeat archived, successful tasks.'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
$this->getTaskSelectionArguments()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute(PhutilArgumentParser $args) {
|
public function execute(PhutilArgumentParser $args) {
|
||||||
$console = PhutilConsole::getConsole();
|
$console = PhutilConsole::getConsole();
|
||||||
$tasks = $this->loadTasks($args);
|
$tasks = $this->loadTasks($args);
|
||||||
|
|
||||||
|
$is_retry = $args->getArg('retry');
|
||||||
|
$is_repeat = $args->getArg('repeat');
|
||||||
|
|
||||||
foreach ($tasks as $task) {
|
foreach ($tasks as $task) {
|
||||||
$can_execute = !$task->isArchived();
|
$can_execute = !$task->isArchived();
|
||||||
if (!$can_execute) {
|
if (!$can_execute) {
|
||||||
$console->writeOut(
|
if (!$is_retry) {
|
||||||
|
$console->writeOut(
|
||||||
|
"**<bg:yellow> %s </bg>** %s\n",
|
||||||
|
pht('ARCHIVED'),
|
||||||
|
pht(
|
||||||
|
'%s is already archived, and will not be executed. '.
|
||||||
|
'Use "--retry" to execute archived tasks.',
|
||||||
|
$this->describeTask($task)));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result_success = PhabricatorWorkerArchiveTask::RESULT_SUCCESS;
|
||||||
|
if ($task->getResult() == $result_success) {
|
||||||
|
if (!$is_repeat) {
|
||||||
|
$console->writeOut(
|
||||||
|
"**<bg:yellow> %s </bg>** %s\n",
|
||||||
|
pht('SUCCEEDED'),
|
||||||
|
pht(
|
||||||
|
'%s has already succeeded, and will not be retried. '.
|
||||||
|
'Use "--repeat" to repeat successful tasks.',
|
||||||
|
$this->describeTask($task)));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
echo tsprintf(
|
||||||
"**<bg:yellow> %s </bg>** %s\n",
|
"**<bg:yellow> %s </bg>** %s\n",
|
||||||
pht('ARCHIVED'),
|
pht('ARCHIVED'),
|
||||||
pht(
|
pht(
|
||||||
'%s is already archived, and can not be executed.',
|
'Unarchiving %s.',
|
||||||
$this->describeTask($task)));
|
$this->describeTask($task)));
|
||||||
continue;
|
|
||||||
|
$task = $task->unarchiveTask();
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: This ignores leases, maybe it should respect them without
|
// NOTE: This ignores leases, maybe it should respect them without
|
||||||
|
|
|
@ -10,15 +10,24 @@ final class PhabricatorWorkerManagementRetryWorkflow
|
||||||
->setSynopsis(
|
->setSynopsis(
|
||||||
pht(
|
pht(
|
||||||
'Retry selected tasks which previously failed permanently or '.
|
'Retry selected tasks which previously failed permanently or '.
|
||||||
'were cancelled. Only archived, unsuccessful tasks can be '.
|
'were cancelled. Only archived tasks can be retried.'))
|
||||||
'retried.'))
|
->setArguments(
|
||||||
->setArguments($this->getTaskSelectionArguments());
|
array_merge(
|
||||||
|
array(
|
||||||
|
array(
|
||||||
|
'name' => 'repeat',
|
||||||
|
'help' => pht(
|
||||||
|
'Repeat tasks which already completed successfully.'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
$this->getTaskSelectionArguments()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute(PhutilArgumentParser $args) {
|
public function execute(PhutilArgumentParser $args) {
|
||||||
$console = PhutilConsole::getConsole();
|
$console = PhutilConsole::getConsole();
|
||||||
$tasks = $this->loadTasks($args);
|
$tasks = $this->loadTasks($args);
|
||||||
|
|
||||||
|
$is_repeat = $args->getArg('repeat');
|
||||||
foreach ($tasks as $task) {
|
foreach ($tasks as $task) {
|
||||||
if (!$task->isArchived()) {
|
if (!$task->isArchived()) {
|
||||||
$console->writeOut(
|
$console->writeOut(
|
||||||
|
@ -32,13 +41,16 @@ final class PhabricatorWorkerManagementRetryWorkflow
|
||||||
|
|
||||||
$result_success = PhabricatorWorkerArchiveTask::RESULT_SUCCESS;
|
$result_success = PhabricatorWorkerArchiveTask::RESULT_SUCCESS;
|
||||||
if ($task->getResult() == $result_success) {
|
if ($task->getResult() == $result_success) {
|
||||||
$console->writeOut(
|
if (!$is_repeat) {
|
||||||
"**<bg:yellow> %s </bg>** %s\n",
|
$console->writeOut(
|
||||||
pht('SUCCEEDED'),
|
"**<bg:yellow> %s </bg>** %s\n",
|
||||||
pht(
|
pht('SUCCEEDED'),
|
||||||
'%s has already succeeded, and can not be retried.',
|
pht(
|
||||||
$this->describeTask($task)));
|
'%s has already succeeded, and will not be repeated. '.
|
||||||
continue;
|
'Use "--repeat" to repeat successful tasks.',
|
||||||
|
$this->describeTask($task)));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$task->unarchiveTask();
|
$task->unarchiveTask();
|
||||||
|
|
Loading…
Reference in a new issue