Differential D21534 Diff 51255 src/infrastructure/daemon/workers/management/PhabricatorWorkerManagementRetryWorkflow.php
Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/daemon/workers/management/PhabricatorWorkerManagementRetryWorkflow.php
| <?php | <?php | ||||
| final class PhabricatorWorkerManagementRetryWorkflow | final class PhabricatorWorkerManagementRetryWorkflow | ||||
| extends PhabricatorWorkerManagementWorkflow { | extends PhabricatorWorkerManagementWorkflow { | ||||
| protected function didConstruct() { | protected function didConstruct() { | ||||
| $this | $this | ||||
| ->setName('retry') | ->setName('retry') | ||||
| ->setExamples('**retry** --id __id__') | ->setExamples('**retry** __selectors__') | ||||
| ->setSynopsis( | ->setSynopsis( | ||||
| pht( | pht( | ||||
| 'Retry selected tasks which previously failed permanently or '. | 'Retry selected tasks which previously failed permanently or '. | ||||
| 'were cancelled. Only archived tasks can be retried.')) | 'were cancelled. Only archived tasks can be retried.')) | ||||
| ->setArguments( | ->setArguments( | ||||
| array_merge( | array_merge( | ||||
| array( | array( | ||||
| array( | array( | ||||
| 'name' => 'repeat', | 'name' => 'repeat', | ||||
| 'help' => pht( | 'help' => pht( | ||||
| 'Repeat tasks which already completed successfully.'), | 'Repeat tasks which already completed successfully.'), | ||||
| ), | ), | ||||
| ), | ), | ||||
| $this->getTaskSelectionArguments())); | $this->getTaskSelectionArguments())); | ||||
| } | } | ||||
| public function execute(PhutilArgumentParser $args) { | public function execute(PhutilArgumentParser $args) { | ||||
| $console = PhutilConsole::getConsole(); | $is_repeat = $args->getArg('repeat'); | ||||
| $tasks = $this->loadTasks($args); | $tasks = $this->loadTasks($args); | ||||
| if (!$tasks) { | |||||
| $this->logWarn( | |||||
| pht('NO TASKS'), | |||||
| pht('No tasks selected to retry.')); | |||||
| $is_repeat = $args->getArg('repeat'); | return 0; | ||||
| } | |||||
| $retry_count = 0; | |||||
| foreach ($tasks as $task) { | foreach ($tasks as $task) { | ||||
| if (!$task->isArchived()) { | if (!$task->isArchived()) { | ||||
| $console->writeOut( | $this->logWarn( | ||||
| "**<bg:yellow> %s </bg>** %s\n", | |||||
| pht('ACTIVE'), | pht('ACTIVE'), | ||||
| pht( | pht( | ||||
| '%s is already in the active task queue.', | '%s is already in the active task queue.', | ||||
| $this->describeTask($task))); | $this->describeTask($task))); | ||||
| continue; | continue; | ||||
| } | } | ||||
| $result_success = PhabricatorWorkerArchiveTask::RESULT_SUCCESS; | $result_success = PhabricatorWorkerArchiveTask::RESULT_SUCCESS; | ||||
| if ($task->getResult() == $result_success) { | if ($task->getResult() == $result_success) { | ||||
| if (!$is_repeat) { | if (!$is_repeat) { | ||||
| $console->writeOut( | $this->logWarn( | ||||
| "**<bg:yellow> %s </bg>** %s\n", | |||||
| pht('SUCCEEDED'), | pht('SUCCEEDED'), | ||||
| pht( | pht( | ||||
| '%s has already succeeded, and will not be repeated. '. | '%s has already succeeded, and will not be repeated. '. | ||||
| 'Use "--repeat" to repeat successful tasks.', | 'Use "--repeat" to repeat successful tasks.', | ||||
| $this->describeTask($task))); | $this->describeTask($task))); | ||||
| continue; | continue; | ||||
| } | } | ||||
| } | } | ||||
| $task->unarchiveTask(); | $task->unarchiveTask(); | ||||
| $console->writeOut( | $this->logInfo( | ||||
| "**<bg:green> %s </bg>** %s\n", | |||||
| pht('QUEUED'), | pht('QUEUED'), | ||||
| pht( | pht( | ||||
| '%s was queued for retry.', | '%s was queued for retry.', | ||||
| $this->describeTask($task))); | $this->describeTask($task))); | ||||
| $retry_count++; | |||||
| } | } | ||||
| $this->logOkay( | |||||
| pht('DONE'), | |||||
| pht('Queued %s task(s) for retry.', new PhutilNumber($retry_count))); | |||||
| return 0; | return 0; | ||||
| } | } | ||||
| } | } | ||||