isometriks / symfony-gearman-bundle
Integrates Gearman into Symfony2
Installs: 17
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 9
Type:symfony-bundle
Requires
- php: >=5.3.0
- ext-gearman: *
- symfony/console: ~2.1
- symfony/framework-bundle: ~2.1
This package is auto-updated.
Last update: 2024-10-24 10:53:18 UTC
README
Installation
composer.json
{ "require": { "laelaps/symfony-gearman-bundle": "1.*@dev" } }
config.yml
laelaps_gearman: servers: - localhost:4730
OR
laelaps_gearman: servers: "localhost:4730,localhost:4731"
app/AppKernel.php
<?php public function registerBundles() { $bundles = array( // ... new Laelaps\GearmanBundle\GearmanBundle(), // ... ); }
Worker supervisor cron tool
There is a simple supervisor bash script available. For instructions, see:
Examples
Worker
<?php // AcmeDemoBundle\Worker\ExampleWorker.php namespace AcmeDemoBundle\Worker; use GearmanJob; use Laelaps\GearmanBundle\Annotation as Gearman; use Laelaps\GearmanBundle\Worker; use Symfony\Component\Console\Output\OutputInterface; class ExampleWorker extends Worker { /** * @Gearman\PointOfEntry(name="example_job_name") * @param GearmanJob $job * @param Symfony\Component\Console\Output\OutputInterface $output * @return boolean returning false means job failure */ public function doExampleJob(GearmanJob $job, OutputInterface $output) { // do your job } }
Running worker
Symfony Style Notation
$ ./app/console gearman:worker:run AcmeBundle:ExampleWorker
Note that this would look for Acme\Bundle\AcmeBundle\Worker\ExampleWorker
$ ./app/console gearman:worker:run ./src/AcmeDemoBundle/Worker/ExampleWorker.php
Wildcard is also available (not recommended but possible - results in single process for multiple workers):
$ ./app/console gearman:worker:run "./src/AcmeDemoBundle/Worker/*.php"
Runs all workers from all bundles:
$ ./app/console gearman:worker:run "./src/*/Worker/*.php"
Calling job from controller
<?php class ExampleController { public function exampleAction() { // job name taken from PointOfEntry annotation $this->get('laelaps.gearman.client')->doBackground('example_job_name', $optionalWorkload = ''); } }
Calling job from command line
$ ./app/console gearman:job:run example_job_name
$ ./app/console gearman:job:run example_job_name optional_workload_string