dev-master
9999999-devyii2 queue component
BSD-4-Clause
The Requires
by Song Yeung
extension yii2 queue
yii2 queue component
This component provides simple queue wrapper, (*1)
I recommend yii2-asynctask., (*2)
Redis yii2-redis, (*3)
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)
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
yii2 queue component
BSD-4-Clause
extension yii2 queue