allow queue to be prefixed

This commit is contained in:
Holger Reinhardt 2016-07-29 15:11:13 +02:00
parent 0663765b47
commit 8d6ebce6b9
2 changed files with 20 additions and 3 deletions

View File

@ -21,6 +21,7 @@ return [
|
*/
'queuePrefix' => env('RESQUE_QUEUE_PREFIX', null),
'trackStatus' => env('RESQUE_TRACK_STATUS', false),
];

View File

@ -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;
}
}