This Symfony bundle provides a high-level way of sending expensive logic to background workers.
composer require "dubture/async-bundle"// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// register the async bundle
new Dubture\AsyncBundle\DubtureAsyncBundle(),
// register the dependencies of the async bundle
new JMS\DiExtraBundle\JMSDiExtraBundle($this),
new JMS\AopBundle\JMSAopBundle(),
// your application bundles here...
);
return $bundles;
}
# app/config/config.yml
dubture_async:
backend: rabbitmq # one of rabbitmq|resque|sonata|runtime
Consider the following service:
<services>
<service class="Acme\Bundle\MediaTranscodingService" id="media_transcoder">
</service>
</services>
class MediaTranscodingService
{
public function transcodeFile($sourcePath)
{
// ... do some heavy-lifting, e.g. media transcoding
}
}
If you want to delegate this method to a background worker, this is all you need to do:
use Dubture\AsyncBundle\Annotation\Async;
class MediaTranscodingService
{
/**
* @Async
*/
public function transcodeFile($sourcePath)
{
// ... do some heavy-lifting, e.g. media transcoding
}
}
Now any call to transcodeFile will be intercepted and delegated to a background worker.
Methods annotated with @Async need to adhere to the following contract:
If you need to react to something happening inside your background worker, you can simply dispatch events when it's done.
The background-worker implementation relies on one of the following bundles:
See Resources/docs for documentation of the specific backends.
How can I help you explore Laravel packages today?