dubture / async-bundle
Provides an easy to use abstraction for async backend workers in Symfony2
Installs: 22
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 4
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- jms/di-extra-bundle: ~1.5
Requires (Dev)
- bcc/resque-bundle: ~1.1
- doctrine/dbal: <2.5
- doctrine/doctrine-bundle: ~1.2
- doctrine/orm: ~2.2,>=2.2.3,<2.5
- oldsound/rabbitmq-bundle: ~1.6
- phpunit/phpunit: ~4.5
- sensio/framework-extra-bundle: ~3.0,>=3.0.2
- sonata-project/admin-bundle: ~2.3
- sonata-project/notification-bundle: ~2.3
- symfony/browser-kit: ~2.2
- symfony/finder: ~2.2
- symfony/monolog-bundle: ~2.2
- symfony/swiftmailer-bundle: ~2.3
Suggests
- bcc/resque-bundle: Backend implementation using resque
- oldsound/rabbitmq-bundle: Backend implementation using rabbitmq
- sonata-project/notification-bundle: The sonata-notification bundle provides multiple backends to choose from
This package is not auto-updated.
Last update: 2024-11-09 18:27:32 UTC
README
This Symfony bundle provides a high-level way of sending expensive logic to background workers.
Configuration
- Install the bundle using
composer require "dubture/async-bundle"
- Add the necessary bundles to your Kernel:
// 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; }
- Configure which backend to use:
# app/config/config.yml dubture_async: backend: rabbitmq # one of rabbitmq|resque|sonata|runtime
Usage
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:
- The class declaring the async method must be a service
- The methods arguments must be serializable (no resources, e.g. doctrine connections)
- The method should not return anything (any return value will be lost)
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:
- https://github.com/michelsalib/BCCResqueBundle (resque)
- https://github.com/videlalvaro/RabbitMqBundle (rabbitmq)
- https://github.com/sonata-project/SonataNotificationBundle (see sonata bundle for available backends)
See Resources/docs
for documentation of the specific backends.