perspectivain/yii2-gearman

Consumer for gearman server

dev-master 2015-03-21 15:08 UTC

This package is not auto-updated.

Last update: 2025-06-21 21:02:48 UTC


README

Component for use gearman server as consumer jobs

Deprecated if Yii2 Queue Component (yiisoft/yii2#492) was accepted

Simple Usage

Register a component

'components' => [
    'gearman' => [
        'class' => 'perspectivain\gearman\Gearman',
        'jobsNamespace' => '\app\jobs\\',
        'servers' => [
            ['host' => GEARMAN_SERVER_HOST, 'port' => GEARMAN_SERVER_PORT],
        ],
    ],
    ...
],

Register a command controller

'controllerMap' => [
    'worker' => [
        'class' => 'perspectivain\gearman\WorkerController'
    ],
    ...
]

Create an job class

namespace app\jobs;

class MyJob implements perspectivain\gearman\InterfaceJob
{
    /**
     * @inheritdoc
     */
    public function run($attributes)
    {
        //do something
    }
}

Register an job in your application

\perspectivain\gearman\BackgroundJob::register('GearmanJob', ['attributeA' => 10]);

Run the worker

# php yii worker/run-one

If your need continuous worker, use the crontab or the supervisor process control system (http://supervisord.org/).

Multi queue Usage

Register an job in your application

$queueName = 'newqueue';
\perspectivain\gearman\BackgroundJob::register('GearmanJob', ['attributeA' => 10], \perspectivain\gearman\BackgroundJob::NORMAL, $queueName);

Run the worker

# php yii worker/run-one newqueue

Installing

The preferred way to install this extension is through composer.

{
  "require": {
    "perspectivain/yii2-gearman": "*"
  }
}