Differential D21534 Diff 51263 src/infrastructure/daemon/workers/management/PhabricatorWorkerManagementCancelWorkflow.php
Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/daemon/workers/management/PhabricatorWorkerManagementCancelWorkflow.php
<?php | <?php | ||||
final class PhabricatorWorkerManagementCancelWorkflow | final class PhabricatorWorkerManagementCancelWorkflow | ||||
extends PhabricatorWorkerManagementWorkflow { | extends PhabricatorWorkerManagementWorkflow { | ||||
protected function didConstruct() { | protected function didConstruct() { | ||||
$this | $this | ||||
->setName('cancel') | ->setName('cancel') | ||||
->setExamples('**cancel** --id __id__') | ->setExamples('**cancel** __selectors__') | ||||
->setSynopsis( | ->setSynopsis( | ||||
pht( | pht( | ||||
'Cancel selected tasks. The work these tasks represent will never '. | 'Cancel selected tasks. The work these tasks represent will never '. | ||||
'be performed.')) | 'be performed.')) | ||||
->setArguments($this->getTaskSelectionArguments()); | ->setArguments($this->getTaskSelectionArguments()); | ||||
} | } | ||||
public function execute(PhutilArgumentParser $args) { | public function execute(PhutilArgumentParser $args) { | ||||
$console = PhutilConsole::getConsole(); | |||||
$tasks = $this->loadTasks($args); | $tasks = $this->loadTasks($args); | ||||
if (!$tasks) { | |||||
$this->logWarn( | |||||
pht('NO TASKS'), | |||||
pht('No tasks selected to cancel.')); | |||||
return 0; | |||||
} | |||||
$cancel_count = 0; | |||||
foreach ($tasks as $task) { | foreach ($tasks as $task) { | ||||
$can_cancel = !$task->isArchived(); | $can_cancel = !$task->isArchived(); | ||||
if (!$can_cancel) { | if (!$can_cancel) { | ||||
$console->writeOut( | $this->logWarn( | ||||
"**<bg:yellow> %s </bg>** %s\n", | |||||
pht('ARCHIVED'), | pht('ARCHIVED'), | ||||
pht( | pht( | ||||
'%s is already archived, and can not be cancelled.', | '%s is already archived, and can not be cancelled.', | ||||
$this->describeTask($task))); | $this->describeTask($task))); | ||||
continue; | continue; | ||||
} | } | ||||
// Forcibly break the lease if one exists, so we can archive the | // Forcibly break the lease if one exists, so we can archive the | ||||
// task. | // task. | ||||
$task->setLeaseOwner(null); | $task | ||||
$task->setLeaseExpires(PhabricatorTime::getNow()); | ->setLeaseOwner(null) | ||||
$task->archiveTask( | ->setLeaseExpires(PhabricatorTime::getNow()); | ||||
PhabricatorWorkerArchiveTask::RESULT_CANCELLED, | |||||
0); | |||||
$console->writeOut( | $task->archiveTask(PhabricatorWorkerArchiveTask::RESULT_CANCELLED, 0); | ||||
"**<bg:green> %s </bg>** %s\n", | |||||
$this->logInfo( | |||||
pht('CANCELLED'), | pht('CANCELLED'), | ||||
pht( | pht( | ||||
'%s was cancelled.', | '%s was cancelled.', | ||||
$this->describeTask($task))); | $this->describeTask($task))); | ||||
$cancel_count++; | |||||
} | } | ||||
$this->logOkay( | |||||
pht('DONE'), | |||||
pht('Cancelled %s task(s).', new PhutilNumber($cancel_count))); | |||||
return 0; | return 0; | ||||
} | } | ||||
} | } |