This extension allow to use MongoDB as queue server without bloating project's stack and provides GUI.
This extension requires MongoDB server version 3.6 or higher. The preferred way to install this extension is through composer. Either run
php composer.phar require --prefer-dist lisio/yii2-mongodb-q
or add
"lisio/yii2-mongodb-q": "~1.0.0"
to the require section of your composer.json.
To use this extension, add the following code to application web configuration:
return [
// ...
'bootstrap' => [
// ...,
'q',
],
'components' => [
// ...
'queue' => [
'class' => '\yii\q\components\QueueServer',
],
],
'modules' => [
// ...
'q' => [
'class' => 'yii\q\Module',
],
],
];
And to application console configuration:
return [
// ...
'controllerMap' => [
// ...
'q' => 'yii\q\commands\QueueController',
],
'components' => [
// ...
'queue' => [
'class' => '\yii\q\components\QueueServer',
],
],
];
Create indexes:
./yii q/create-indexes
This extension provides sample code for different cases (see folder examples/
).
Yii::$app->queue->queueCreate('test');
Yii::$app->queue->queuePurge('test');
Yii::$app->queue->queueRemove('test');
$data = [
'someParam' => 'someValue',
];
$options = [
'keepResult' => true,
'keepResultDuration' => 86400,
];
$job = Yii::$app->queue->jobCreate('test', SomeWorker::className(), $data, $options);
Yii::$app->queue->jobPause($job->_id);
Yii::$app->queue->jobResume($job->_id);
Yii::$app->queue->jobRemove($job->_id);
Yii::$app->queue->jobRetry($job->_id);
Yii::$app->queue->jobStatus($job->_id);
./yii q/spawn
./yii q/spawn 3 download,report
./yii q/remove-dead-workers
./yii q/remove-stale-jobs
./yii q/stop-workers download,report
./yii q/stop-workers
./yii q/stop-all-workers
GUI can be accessed at http://your.project.com/q.