wayhood/yii2-asynctask

a queue extension using redis for yii2

Installs: 490

Dependents: 0

Suggesters: 0

Security: 0

Stars: 15

Watchers: 4

Forks: 2

Open Issues: 1

Type:yii2-extension

dev-master 2016-08-11 19:09 UTC

This package is auto-updated.

Last update: 2024-11-07 17:27:31 UTC


README

a async task process module using redis for yii2

Installation

The preferred way to install this extension is through composer.

Either run

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

or add

"wayhood/yii2-asynctask": "*"

to the require section of your composer.json file.

Usage

To use this module in a web application. simply add the following code in your application configuration:

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

To use this module in a console application. like to web application

run

./yii asynctask "a, b, c"  

a, b and c was queue name.

CREATE WORKER FILE

<?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.

// 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');