Differential D21534 Diff 51255 src/infrastructure/daemon/workers/management/PhabricatorWorkerManagementFreeWorkflow.php
Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/daemon/workers/management/PhabricatorWorkerManagementFreeWorkflow.php
| <?php | <?php | ||||
| final class PhabricatorWorkerManagementFreeWorkflow | final class PhabricatorWorkerManagementFreeWorkflow | ||||
| extends PhabricatorWorkerManagementWorkflow { | extends PhabricatorWorkerManagementWorkflow { | ||||
| protected function didConstruct() { | protected function didConstruct() { | ||||
| $this | $this | ||||
| ->setName('free') | ->setName('free') | ||||
| ->setExamples('**free** --id __id__') | ->setExamples('**free** __selectors__') | ||||
| ->setSynopsis( | ->setSynopsis( | ||||
| pht( | pht( | ||||
| 'Free leases on selected tasks. If the daemon holding the lease is '. | 'Free leases on selected tasks. If the daemon holding the lease is '. | ||||
| 'still working on the task, this may cause the task to execute '. | 'still working on the task, this may cause the task to execute '. | ||||
| 'twice.')) | 'twice.')) | ||||
| ->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 free leases on.')); | |||||
| return 0; | |||||
| } | |||||
| $free_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('ARCHIVED'), | pht('ARCHIVED'), | ||||
| pht( | pht( | ||||
| '%s is archived; archived tasks do not have leases.', | '%s is archived; archived tasks do not have leases.', | ||||
| $this->describeTask($task))); | $this->describeTask($task))); | ||||
| continue; | continue; | ||||
| } | } | ||||
| if ($task->getLeaseOwner() === null) { | if ($task->getLeaseOwner() === null) { | ||||
| $console->writeOut( | $this->logWarn( | ||||
| "**<bg:yellow> %s </bg>** %s\n", | |||||
| pht('FREE'), | pht('FREE'), | ||||
| pht( | pht( | ||||
| '%s has no active lease.', | '%s has no active lease.', | ||||
| $this->describeTask($task))); | $this->describeTask($task))); | ||||
| continue; | continue; | ||||
| } | } | ||||
| $task->setLeaseOwner(null); | $task | ||||
| $task->setLeaseExpires(PhabricatorTime::getNow()); | ->setLeaseOwner(null) | ||||
| $task->save(); | ->setLeaseExpires(PhabricatorTime::getNow()) | ||||
| ->save(); | |||||
| $console->writeOut( | $this->logInfo( | ||||
| "**<bg:green> %s </bg>** %s\n", | |||||
| pht('LEASE FREED'), | pht('LEASE FREED'), | ||||
| pht( | pht( | ||||
| '%s was freed from its lease.', | '%s was freed from its lease.', | ||||
| $this->describeTask($task))); | $this->describeTask($task))); | ||||
| $free_count++; | |||||
| } | } | ||||
| $this->logOkay( | |||||
| pht('DONE'), | |||||
| pht('Freed %s task lease(s).', new PhutilNumber($free_count))); | |||||
| return 0; | return 0; | ||||
| } | } | ||||
| } | } | ||||