An optionated helper for dealing with queues
Via Composer
$ composer require arrounded/queues
A Laravel 4.2 version also availabe: composer require arrounded/queues:dev-laravel/4.2
First add the module's service provider and facade to config/app.php:
Arrounded\Queues\ServiceProvider::class
'Queues' => Arrounded\Queues\Facades\Queues::class,
Now you can start using the helper in your application code via the Facade:
Queues::on('foo')->uses(Foobar::class)->push()
This will push a job on the local_foo_normal
queue.
Priorities
Queues::on('foo')->uses(Foobar::class)->priority(Queues::PRIORITY_HIGH)->push();
This will push a job on the local_foo_high
queue.
Passing a payload
Queues::on('foo')->uses(Foobar::class)->with([
'bar' => 'foo'
])->push();
This will push a job on the local_foo_normal
queue with a {'bar': 'foo'}
payload
Delaying execution
Queues::on('foo')->uses(Foobar::class)->delay(10)->push();
This will delay the execution of the job by 10 seconds.
The default behavior is to prefix all queues with the current app environment. If you want to overwrite this default on an application level, you can do it in your own ServiceProvider:
$this->app['queues']->setPrefix('foobar') // foobar_foo_normal
Disabling queueing
In some cases you might want to disable queueing all together (for example during integration/functional tests)
// To disable
$this->app['queues']->disabled()
// To re-enable
$this->app['queues']->disabled(false)
You can also use dependency injection:
use Arrounded\Queues\Queues;
class FooService
{
public function __construct(Queues $queues)
{
$this->queues = $queues;
}
$ composer test
The MIT License (MIT). Please see License File for more information.