From 8d6ebce6b904feadb532f56e18045c4b978caf13 Mon Sep 17 00:00:00 2001 From: Holger Reinhardt Date: Fri, 29 Jul 2016 15:11:13 +0200 Subject: [PATCH] allow queue to be prefixed --- config/resque.php | 1 + src/ResqueManager.php | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/config/resque.php b/config/resque.php index a1cfa11..d10dd65 100644 --- a/config/resque.php +++ b/config/resque.php @@ -21,6 +21,7 @@ return [ | */ + 'queuePrefix' => env('RESQUE_QUEUE_PREFIX', null), 'trackStatus' => env('RESQUE_TRACK_STATUS', false), ]; diff --git a/src/ResqueManager.php b/src/ResqueManager.php index 3d9fe03..3195ad3 100644 --- a/src/ResqueManager.php +++ b/src/ResqueManager.php @@ -2,7 +2,6 @@ namespace Hlgrrnhrdt\Resque; use Resque; -use Resque_Worker; use RuntimeException; /** @@ -17,6 +16,11 @@ class ResqueManager */ protected $resque; + /** + * @var string + */ + protected $queuePrefix; + /** * @var bool */ @@ -26,12 +30,14 @@ class ResqueManager * ResqueManager constructor. * * @param \Resque $resque + * @param string $queuePrefix * @param bool $trackStatus */ - public function __construct(Resque $resque, $trackStatus = false) + public function __construct(Resque $resque, $queuePrefix, $trackStatus = false) { $this->resque = $resque; $this->trackStatus = $trackStatus; + $this->queuePrefix = $queuePrefix; } /** @@ -42,7 +48,7 @@ class ResqueManager */ public function enqueue(Job $job, $trackStatus = false) { - $id = $this->resque->enqueue($job->queue(), get_class($job), $job->arguments(), $trackStatus); + $id = $this->resque->enqueue($this->getQueueName($job), get_class($job), $job->arguments(), $trackStatus); if (true === $trackStatus) { return new \Resque_Job_Status($id); @@ -108,4 +114,14 @@ class ResqueManager return $queuedJob->payload['class'] === get_class($queuedJob) && count(array_intersect($queuedJob->getArguments(), $job->arguments())) === count($job->arguments()); } + + private function getQueueName(Job $job) + { + $queue = $job->queue(); + if ($this->queuePrefix) { + $queue = implode(':', [$this->queuePrefix, $queue]); + } + + return $queue; + } }