2017 © Pedro Peláez
 

yii2-extension catena

Redis based queued background jobs system

image

comradefuzz/catena

Redis based queued background jobs system

  • Tuesday, May 23, 2017
  • by comradefuzz
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Catena

Redis based queued background jobs system inspired by resque, (*1)

Installation

The preferred way to install this extension is through composer., (*2)

Either run, (*3)

php composer.phar require --prefer-dist comradefuzz/catena "*"

or add, (*4)

"comradefuzz/catena": "*"

to the require section of your composer.json file., (*5)

Attention

Module is in development mode and should not be used in production, (*6)

Usage

Configure your application like following:, (*7)

 'bootstrap' => ['catena'],
 'components' => [
    'queue' => 'comradefuzz\catena\components\Queue',
 ],
 'modules' => [
        'catena' => [
            'class' => 'comradefuzz\catena\Module',
            'autoRespawn' => false, // If set worker groups will be kept in actual state by respawning dead workers
                                    // (defaults `false`)
            'enableRegulars' => false,  // If this is set and `regularJobs` is not empty, jobs will be automatically set
                                        // to queues with specified interval (defaults `false`)
            'redis' => [
                // Redis connection
                'connection' => [
                    'class' => '\yii\redis\Connection',
                    'hostname' => 'redis',
                ],
                'namespace' => 'catena', // prefix all module data has (defaults to `catena`)
            ],
            // Worker groups configuration
            'workers' => [
                [
                    'queues' => 'harder', // define queues workers are listening to
                    'count' => 3, // specify workers count in group (more workers means faster processing)
                    'sleep' => 15, // number of seconds each worker sleeps if all jobs are done
                    'memoryLimit' => 3 * 1024 * 1024 // bytes of RAM allowed to use to each worker in group
                ],
                [
                    'queues' => 'better,stronger', // you can define several queues to worker group
                    'count' => 2
                ],
                ['queues' => 'faster'],
            ],
            'regularJobs' => [
                [
                    '\app\jobs\RegularJob', // Job class
                    'queue' => 'harder',    // Queue to place job
                    'args' => ['foo' => 'bar'], // Job arguments
                    'interval' => 15    // Interval in seconds in which job will be enqueued
                ],
                [
                    '\app\jobs\RegularJob',
                    'queue' => 'harder',
                    'args' => ['foo' => 'bazzz'],
                    'interval' => 15,
                    'descriptor' => 'another', // Allows to have several regular jobs of one class with different arguments
                ],
            ]
        ]
    ],
 ```

 Define job class

 ```
 <?php
 namespace app\jobs;

 use comradefuzz\catena\models\BaseJob;

 class MyJob extends BaseJob
 {
     public $foo;
     public $bar;

     public function rules()
     {
        return [
            [['foo', 'bar'], 'string'],
            ['foo', 'required'],
        ];
     }
     public function perform()
     {
         \Yii::info("Job is done!");
     }
 }

Now you can run this job in background:, (*8)

Yii::$app->queue->push(new \app\jobs\MyJob(['foo' => 'bar']), 'heavy');

Then start catena daemons yii catena/start. See module status using yii catena/status. Stop daemons with yii catena/stop., (*9)

The Versions

23/05 2017

dev-master

9999999-dev

Redis based queued background jobs system

  Sources   Download

GPL-3.0+

The Requires

 

by Fuzz

yii2 redis queue extension background

23/05 2017

1.0.0

1.0.0.0

Redis based queued background jobs system

  Sources   Download

GPL-3.0+

The Requires

 

by Fuzz

yii2 redis queue extension background