Skip to content

Commit

Permalink
Fix move command to allow move from buried and delayed states.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmatseykanets committed Sep 5, 2015
1 parent b42eaf0 commit 24616de
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/Console/MoveCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ public function handle()
}

$moved = 0;
while ($job = $this->reserveJob($this->argument('from'))) {
while ($job = $this->getNextJob($this->argument('from'), $this->state)) {
if ($this->count > 0 && $moved >= $this->count) {
break;
}

// Read the job's stats in order to preserve priority and ttr
$stats = $this->getJobStats($job);

$this->putJob($this->argument('to'), $job->getData(), $this->priority ?: $stats['pri'], $this->delay, $this->ttr ?: $stats['ttr']);
Expand Down Expand Up @@ -96,4 +96,22 @@ protected function parseCommandArguments()
}
}
}

/**
* Fetches the next job from the tube.
* For ready jobs do reserve, for delayed and buried - peek.
*
* @param $tube
* @param $state
*
* @return bool|object|\Pheanstalk\Job|void
*/
private function getNextJob($tube, $state)
{
if ('ready' == $this->state) {
return $this->reserveJob($tube);
}

return $this->peekJob($tube, $state);
}
}

0 comments on commit 24616de

Please sign in to comment.