From fd166bbe821c4f951264b16c8e5cbce394f7fd6a Mon Sep 17 00:00:00 2001 From: Holger Reinhardt Date: Fri, 29 Jul 2016 15:15:35 +0200 Subject: [PATCH] Apply queue prefix on everything --- src/Console/WorkCommand.php | 10 +++++++--- src/ResqueManager.php | 17 ++++++++++++++--- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/Console/WorkCommand.php b/src/Console/WorkCommand.php index e7769bc..325ba38 100644 --- a/src/Console/WorkCommand.php +++ b/src/Console/WorkCommand.php @@ -42,7 +42,7 @@ class WorkCommand extends IlluminateCommand */ public function fire() { - $queue = $this->option('queue'); + $queues = $this->option('queue'); $interval = (int)$this->option('interval'); $count = (int)$this->option('count'); @@ -59,11 +59,11 @@ class WorkCommand extends IlluminateCommand } if (0 === $pid) { - $this->startWorker($queue, $interval, $logLevel); + $this->startWorker($queues, $interval, $logLevel); } } } else { - $this->startWorker($queue, $interval, $logLevel); + $this->startWorker($queues, $interval, $logLevel); } return 0; @@ -76,6 +76,10 @@ class WorkCommand extends IlluminateCommand */ private function startWorker(array $queues, $interval = 5, $logLevel = Resque_Worker::LOG_NONE) { + $queues = array_walk($queues, function ($queue) { + return $this->manager->getQueue($queue); + }); + $worker = new Resque_Worker($queues); $worker->logLevel = $logLevel; diff --git a/src/ResqueManager.php b/src/ResqueManager.php index 3195ad3..a54af90 100644 --- a/src/ResqueManager.php +++ b/src/ResqueManager.php @@ -48,7 +48,7 @@ class ResqueManager */ public function enqueue(Job $job, $trackStatus = false) { - $id = $this->resque->enqueue($this->getQueueName($job), get_class($job), $job->arguments(), $trackStatus); + $id = $this->resque->enqueue($this->getQueueFromJob($job), get_class($job), $job->arguments(), $trackStatus); if (true === $trackStatus) { return new \Resque_Job_Status($id); @@ -65,7 +65,7 @@ class ResqueManager */ public function enqueueOnce(Job $job, $trackStatus = false) { - $queue = new Queue($job->queue()); + $queue = new Queue($this->getQueueFromJob($job)); foreach ($queue->jobs() as $queuedJob) { if (true === $this->isDuplicateJob($job, $queuedJob)) { @@ -115,9 +115,20 @@ class ResqueManager && count(array_intersect($queuedJob->getArguments(), $job->arguments())) === count($job->arguments()); } - private function getQueueName(Job $job) + private function getQueueFromJob(Job $job) { $queue = $job->queue(); + + return $this->getQueue($queue); + } + + /** + * @param string $queue + * + * @return string + */ + public function getQueue($queue) + { if ($this->queuePrefix) { $queue = implode(':', [$this->queuePrefix, $queue]); }