Yii2 extension to provide SQL based queue worker
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist macklus/yii2-simple-queue "*"
or add
"macklus/yii2-simple-queue": "*"
to the require section of your composer.json
file.
Once the extension is installed, configure it define queue component :
'queue' => [
'class' => 'macklus\SimpleQueue\SimpleQueue',
'connection' => 'db',
'table' => 'simpleQueue',
'persistent' => true,
'duplicate_jobs' => false,
],
Optional vars are:
Once the extension is configured, simply use it to put a job on a queue:
Yii::$app->queue->putInTube($queue, [array_of_vars_of_job]);
You need a controller to get (and process) all jobs. In example:
<?php
namespace app\commands;
use macklus\SimpleQueue\SimpleQueueController;
class SqController extends SimpleQueueController
{
const DELAY_PRIORITY = 1000; //Default priority
const DELAY_TIME = 60; //Default delay time
const DELAY_MAX = 3;
public function listenTubes()
{
return ['test'];
}
public function actionTest($job)
{
$jobData = $job->getData();
// do some stuff
return self::DELETE;
}
}
Comments