Developed with love by KnpLabs Hire us for your project!
21

symfony-gearman-bundle

by laelaps

This bundle is finished and ready for production purposes.

Symfony Gearman Bundle

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\LaelapsGearmanBundle(),
        // ...
    );
}

Worker supervisor cron tool

There is a simple supervisor bash script available. For instructions, see:

https://github.com/laelaps/symfony-gearman-bundle/issues/2#issuecomment-16257507

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
Copyright (c) 2014 laelaps

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
laelaps_gearman:
servers: ~ # Required
  • Support logger for multiple Gearman clients.
    By istaveren, 3 years ago
  • Show the request to gearman when possible.
    By istaveren, 3 years ago
  • Merge branch 'master' of github.com:laelaps/symfony-gearman-bundle
    By istaveren, 3 years ago
  • Create LICENSE
    By mcharytoniuk, 3 years ago
  • Adding collector information and twig template
    By istaveren, 4 years ago
  • Remove old Extension
    By isometriks, 4 years ago
  • Remove old Extension
    By isometriks, 4 years ago
  • Allowed usage of Symfony-style notation to init workers.
    By isometriks, 4 years ago
  • Dynamic servers
    By isometriks, 4 years ago
  • Updated readme
    By isometriks, 4 years ago
  • Rename Bundle so it has proper namespace "laelaps_gearman" instead of "gearman"
    By isometriks, 4 years ago
  • Added semantic config
    By isometriks, 4 years ago
  • Removed PHP 5.4 array syntax shortcut: https://wiki.php.net/rfc/shortsyntaxforarrays
    By mcharytoniuk, 4 years ago
  • Removed PHP 5.4 call method from array syntax. Using call_user_func_array http://php.net/manual/en/function.call-user-func-array.php
    By mcharytoniuk, 4 years ago
  • Update PHP 5.4 dependency => PHP 5.3
    By mcharytoniuk, 4 years ago
  • Merge pull request #3 from kl3ryk/master
    By mcharytoniuk, 4 years ago
  • composer dependencies updated
    By kl3ryk, 4 years ago
  • Update README.md
    By mcharytoniuk, 4 years ago
  • Create php-watcher.sh
    By mcharytoniuk, 4 years ago
  • Merge branch 'master' of github.com:laelaps/symfony-gearman-bundle
    By mcharytoniuk, 4 years ago
  • RunWorkerCommand refactoring
    By mcharytoniuk, 4 years ago
  • RunWorkerCommand refactoring
    By mcharytoniuk, 4 years ago
  • forced gc collecting cycles
    By mcharytoniuk, 4 years ago
  • container call fix
    By mcharytoniuk, 4 years ago
  • RunWorkerCommand improvements
    By mcharytoniuk, 4 years ago
  • Merge branch 'master' of github.com:laelaps/symfony-gearman-bundle
    By mcharytoniuk, 4 years ago
  • more verbose error messages
    By mcharytoniuk, 4 years ago
  • Update Resources/config/services.yml
    By mcharytoniuk, 4 years ago
  • Update README.md
    By mcharytoniuk, 4 years ago
  • Update README.md
    By mcharytoniuk, 4 years ago