2017 © Pedro Peláez
 

yii2-extension yii2-queue

yii2 queue component

image

wayhood/yii2-queue

yii2 queue component

  • Sunday, January 3, 2016
  • by yiitech
  • Repository
  • 6 Watchers
  • 20 Stars
  • 6,997 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 14 Forks
  • 3 Open issues
  • 1 Versions
  • 8 % Grown

The README.md

Queue component for Yii2

This component provides simple queue wrapper, (*1)

I recommend yii2-asynctask., (*2)

Requirements

Redis yii2-redis, (*3)

Installation

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

Either run, (*5)

php composer.phar require --prefer-dist wayhood/yii2-queue "*"

or add, (*6)

"wayhood/yii2-queue": "*"

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

Usage

To use this extension, simply add the following code in your application configuration:, (*8)

return [
    //....
    'components' => [
        'queue' => [
            'class' => 'wh\queue\RedisQueue',
        ],
        'redis' => [
            'class' => 'yii\redis\Connection',
            'hostname' => 'localhost',
            'port' => 6379,
            'database' => 0
        ],
    ],
];

First create a Job process class, (*9)

namespace console\jobs;

class MyJob
{
    public function run($job, $data)
    {
        //process $data;
        var_dump($data);
    }
} 

and than just push job to queue, (*10)

// Push job to the default queue and execute "run" method
Yii::$app->queue->push('\console\jobs\MyJob', ['a', 'b', 'c']);

// or push it and execute any other method
Yii::$app->queue->push('\console\jobs\MyJob@myMethod', ['a', 'b', 'c']);

// or push it to some specific queue
Yii::$app->queue->push('\console\jobs\MyJob', ['a', 'b', 'c'], 'myQueue');

// or both
Yii::$app->queue->push('\console\jobs\MyJob@myMethod', ['a', 'b', 'c'], 'myQueue');

Map console controller in your app config, (*11)

return [
    ...
    'controllerMap' => [
        'queue' => 'wh\queue\console\controllers\QueueController'
    ],
    ...
];

Examples of using queue controller:, (*12)

# Process a job from default queue and than exit the process
./yii queue/work

# continuously process jobs from default queue
./yii queue/listen

# process a job from specific queue and than exit the process
./yii queue/work myQueue

# continuously process jobs from specific queue
./yii queue/listen myQueue

The Versions

03/01 2016

dev-master

9999999-dev

yii2 queue component

  Sources   Download

BSD-4-Clause

The Requires

 

by Song Yeung

extension yii2 queue