Skip to content

Commit

Permalink
Merge pull request #19 from uafrica/allow-paused-requeue
Browse files Browse the repository at this point in the history
Allow paused (status 9) jobs to be requeued
  • Loading branch information
dakota committed Jun 15, 2018
2 parents d069fcc + 68de304 commit 92304f7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/Model/Entity/DelayedJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
/**
* Class DelayedJob
*
* @property int $status
* @property \Cake\I18n\Time $run_at
*
* @internal
Expand Down
29 changes: 20 additions & 9 deletions src/Shell/WatchdogShell.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,19 +373,30 @@ public function reload()

public function requeue()
{
/** @var \DelayedJobs\Model\Entity\DelayedJob $job */
$job = TableRegistry::get('DelayedJobs.DelayedJobs')
->get($this->args[0]);

if ($job->status === Job::STATUS_NEW || $job->status === Job::STATUS_FAILED) {
if (JobManager::instance()->enqueuePersisted($job['id'], $job['priority'])) {
$this->out(' :: <success>√</success>', 1, Shell::VERBOSE);
} else {
$this->out(' :: <error>X</error>', 1, Shell::VERBOSE);
}
$this->out(__('<success>{0} has been queued</success>', $job->id));
} else {
$this->out(__('<error>{0} could not be queued</error>', $job->id));
if (!in_array($job->status, [
Job::STATUS_NEW,
Job::STATUS_FAILED,
Job::STATUS_PAUSED,
])) {
$this->out(__('<error>{0} could not be queued - status is {1}</error>', $job->id, $job->status));

return false;
}

if (!JobManager::instance()->enqueuePersisted($job['id'], $job['priority'])) {
$this->out(' :: <error>X</error>', 1, Shell::VERBOSE);

return false;
}

$this->out(' :: <success>√</success>', 1, Shell::VERBOSE);
$this->out(__('<success>{0} has been queued</success>', $job->id));

return true;
}

public function revive()
Expand Down

0 comments on commit 92304f7

Please sign in to comment.