2017 © Pedro Peláez
 

yii2-extension yii2-asynctask

a queue extension using redis for yii2

image

wayhood/yii2-asynctask

a queue extension using redis for yii2

  • Thursday, August 11, 2016
  • by yiitech
  • Repository
  • 4 Watchers
  • 16 Stars
  • 416 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Async Task module for Yii2

a async task process module using redis for yii2, (*1)

Installation

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

Either run, (*3)

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

or add, (*4)

"wayhood/yii2-asynctask": "*"

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

Usage

To use this module in a web application. simply add the following code in your application configuration:, (*6)

reutrn [
    'bootstrap' => [..., 'asynctask'],
    'modules' => [
        'asynctask' => [
            'class' => 'wh\asynctask\Module',
            'redis' => 'redis' /* or [
                'class' => 'yii\redis\Connection',
                'hostname' => 'localhost',
                'port' => 6379,
                'database' => 0,
            ]*/
        ]
    ],
    ...
];

http://path/to/index.php?r=asynctask, (*7)

To use this module in a console application. like to web application, (*8)

run, (*9)

./yii asynctask "a, b, c"  
````

a, b and c was queue name.


CREATE WORKER FILE

```php
<?php
/**
 * @link http://www.wayhood.com/
 */

namespace frontend\workers;

/**
 * Class TestWorker
 * @package frontend\workers
 * @author Song Yeung <netyum@163.com>
 * @date 12/20/14
 */
class TestWorker extends \wh\asynctask\Worker
{
    protected static $queue = 'abc'; //a queue name

    protected static $redis = 'reids' //or a configure array.

    public static function run($a, $b)
    {
        var_dump($a); //real process code
        var_dump($b);
    }
}

CALL THE WORKER IN CONTROLLER OR MODEL AND ANYWHERE., (*10)

// run one time
    \frontend\workers\TestWorker::runAysnc('a', 'b');
// run after 10 sec
    \frontend\workers\TestWorker::runIn('10s', 'a', 'b');
// run each 10 min
    \frontend\workers\TestWorker::runEach('10m', 'a', 'b');

The Versions

11/08 2016

dev-master

9999999-dev

a queue extension using redis for yii2

  Sources   Download

Apache-2.0

The Requires

 

by Song Yeung

yii2 redis queue job worker