Skip to content

Commit

Permalink
Merge branch 'queue-prefix' of https://github.com/browner12/framework
Browse files Browse the repository at this point in the history
…into browner12-queue-prefix
  • Loading branch information
taylorotwell committed Apr 21, 2017
2 parents befcfbc + 6640139 commit 465805d
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Queue/BeanstalkdQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public function deleteMessage($queue, $id)
*/
public function getQueue($queue)
{
return $queue ?: $this->default;
return $this->getQueuePrefix().($queue ?: $this->default);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/Illuminate/Queue/Console/ListenCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,11 @@ protected function getQueue($connection)
{
$connection = $connection ?: $this->laravel['config']['queue.default'];

return $this->input->getOption('queue') ?: $this->laravel['config']->get(
$queue = $this->input->getOption('queue') ?: $this->laravel['config']->get(
"queue.connections.{$connection}.queue", 'default'
);

return $this->laravel['config']->get('queue.prefix', null).$queue;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/Illuminate/Queue/Console/WorkCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,11 @@ protected function logFailedJob(JobFailed $event)
*/
protected function getQueue($connection)
{
return $this->option('queue') ?: $this->laravel['config']->get(
$queue = $this->option('queue') ?: $this->laravel['config']->get(
"queue.connections.{$connection}.queue", 'default'
);

return $this->laravel['config']->get('queue.prefix', null).$queue;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Queue/DatabaseQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ public function deleteReserved($queue, $id)
*/
protected function getQueue($queue)
{
return $queue ?: $this->default;
return $this->getQueuePrefix().($queue ?: $this->default);
}

/**
Expand Down
30 changes: 30 additions & 0 deletions src/Illuminate/Queue/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ abstract class Queue
*/
protected $connectionName;

/**
* The queue prefix.
*
* @var string
*/
protected $queuePrefix;

/**
* Push a new job onto the queue.
*
Expand Down Expand Up @@ -188,4 +195,27 @@ public function setContainer(Container $container)
{
$this->container = $container;
}

/**
* Set the queue prefix.
*
* @param string $prefix
* @return $this
*/
public function setQueuePrefix($prefix = null)
{
$this->queuePrefix = $prefix;

return $this;
}

/**
* Get the queue prefix.
*
* @return string
*/
public function getQueuePrefix()
{
return $this->queuePrefix;
}
}
13 changes: 12 additions & 1 deletion src/Illuminate/Queue/QueueManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ protected function resolve($name)

return $this->getConnector($config['driver'])
->connect($config)
->setConnectionName($name);
->setConnectionName($name)
->setQueuePrefix($this->getQueuePrefix());
}

/**
Expand Down Expand Up @@ -232,6 +233,16 @@ public function setDefaultDriver($name)
$this->app['config']['queue.default'] = $name;
}

/**
* Get the name of the queue prefix.
*
* @return string
*/
public function getQueuePrefix()
{
return $this->app['config']->get('queue.prefix');
}

/**
* Get the full name for the given connection.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Queue/RedisQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ protected function getRandomId()
*/
protected function getQueue($queue)
{
return 'queues:'.($queue ?: $this->default);
return 'queues:'.$this->getQueuePrefix().($queue ?: $this->default);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Queue/SqsQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function pop($queue = null)
*/
public function getQueue($queue)
{
$queue = $queue ?: $this->default;
$queue = $this->getQueuePrefix().($queue ?: $this->default);

return filter_var($queue, FILTER_VALIDATE_URL) === false
? rtrim($this->prefix, '/').'/'.$queue : $queue;
Expand Down
32 changes: 21 additions & 11 deletions tests/Queue/QueueManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Mockery as m;
use PHPUnit\Framework\TestCase;
use Illuminate\Config\Repository;
use Illuminate\Queue\QueueManager;

class QueueManagerTest extends TestCase
Expand All @@ -15,18 +16,21 @@ public function tearDown()

public function testDefaultConnectionCanBeResolved()
{
$config = new Repository([
'queue.default' => 'sync',
'queue.connections.sync' => ['driver' => 'sync'],
]);

$app = [
'config' => [
'queue.default' => 'sync',
'queue.connections.sync' => ['driver' => 'sync'],
],
'config' => $config,
'encrypter' => $encrypter = m::mock('Illuminate\Contracts\Encryption\Encrypter'),
];

$manager = new QueueManager($app);
$connector = m::mock('StdClass');
$queue = m::mock('StdClass');
$queue->shouldReceive('setConnectionName')->once()->with('sync')->andReturnSelf();
$queue->shouldReceive('setQueuePrefix')->once()->with('')->andReturnSelf();
$connector->shouldReceive('connect')->once()->with(['driver' => 'sync'])->andReturn($queue);
$manager->addConnector('sync', function () use ($connector) {
return $connector;
Expand All @@ -38,18 +42,21 @@ public function testDefaultConnectionCanBeResolved()

public function testOtherConnectionCanBeResolved()
{
$config = new Repository([
'queue.default' => 'sync',
'queue.connections.foo' => ['driver' => 'bar'],
]);

$app = [
'config' => [
'queue.default' => 'sync',
'queue.connections.foo' => ['driver' => 'bar'],
],
'config' => $config,
'encrypter' => $encrypter = m::mock('Illuminate\Contracts\Encryption\Encrypter'),
];

$manager = new QueueManager($app);
$connector = m::mock('StdClass');
$queue = m::mock('StdClass');
$queue->shouldReceive('setConnectionName')->once()->with('foo')->andReturnSelf();
$queue->shouldReceive('setQueuePrefix')->once()->with('')->andReturnSelf();
$connector->shouldReceive('connect')->once()->with(['driver' => 'bar'])->andReturn($queue);
$manager->addConnector('bar', function () use ($connector) {
return $connector;
Expand All @@ -61,17 +68,20 @@ public function testOtherConnectionCanBeResolved()

public function testNullConnectionCanBeResolved()
{
$config = new Repository([
'queue.default' => 'null',
]);

$app = [
'config' => [
'queue.default' => 'null',
],
'config' => $config,
'encrypter' => $encrypter = m::mock('Illuminate\Contracts\Encryption\Encrypter'),
];

$manager = new QueueManager($app);
$connector = m::mock('StdClass');
$queue = m::mock('StdClass');
$queue->shouldReceive('setConnectionName')->once()->with('null')->andReturnSelf();
$queue->shouldReceive('setQueuePrefix')->once()->with('')->andReturnSelf();
$connector->shouldReceive('connect')->once()->with(['driver' => 'null'])->andReturn($queue);
$manager->addConnector('null', function () use ($connector) {
return $connector;
Expand Down

0 comments on commit 465805d

Please sign in to comment.