Download the PHP package horrible/gearman-bundle without Composer
On this page you can find all versions of the php package horrible/gearman-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download horrible/gearman-bundle
More information about horrible/gearman-bundle
Files in horrible/gearman-bundle
Informations about the package gearman-bundle
Horrible Gearman Bundle Documentation
Configuration
-
Add following configuration to your config.yml:
- servers - an array of the gearman servers, you can ignore 'port' field, gearman's default port will be used.
- retries - amount of retries if exception would be thrown from Job
-
Add bundle initialization to the app/AppKernel.php
-
Create your own Job implemeting JobInterface. It's important to give your job name (so you can access your job through client using this job name). Also implement your 'execute' method where you can get WorkloadInterface instance.
-
Register your Job as a service and add tag with the name 'horrible.gearman.job' to it
services.yml
-
Start workers
To have workers started you should call command 'horrible:worker:work'. If you have to have your worker started in background you could do:
Symfony < 3 version
Symfony >= 3 version
-
Add a task through client
SomeController.php
Workload data will be encoded as json (in case of SimpleWorkload usage) and passed to Gearman, and you will get it as WorkloadInterface instance in your Job->execute method
Mainly all 'horrible.gearman.client' methods are the same as in the GearmanClient (http://php.net/manual/ru/class.gearmanclient.php) but instead of workload as a string it uses WorkloadInterface instance
Workload is not required parameter, if you'd skip it you'll get WorkloadInterface instance in your job which will have '0' inside as a value
Events
Bundle has several types of events:
-
JobStartedEvent ('horrible.event.job.started') - fired before job has been started, contains:
- $jobName (string)
- $workload (WorkloadInterface instance)
- $workerId (string) - worker id which is processing current job
-
JobFinishedEvent ('horrible.event.job.finished') - fired after successfully finished job, contains:
- $jobName (string)
- $workload (WorkloadInterface instance)
- $jobResult (mixed) - data which is returned from the Job->execute() method
- $workerId (string) - worker id which is processing current job
- JobFailedEvent ('horrible.event.job.failed') - fired before job has been started, contains:
- $jobName (string)
- $workload (WorkloadInterface instance)
- $exception (object) - Exception instance that was thrown out of the job
- $workerId (string) - worker id which is processing current job
To catch these events you should use tags:
services.yml
MyEventListener