lisio/yii2-mongodb-q

MongoDB Queue Server extension for the Yii framework

Installs: 32

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 2

Forks: 0

Type:yii2-extension

1.0.5 2020-05-27 01:49 UTC

This package is not auto-updated.

Last update: 2024-05-08 21:05:04 UTC


README

This extension allow to use MongoDB as queue server without bloating project's stack and provides GUI.

Installation

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.

Configuration

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

Usage

This extension provides sample code for different cases (see folder examples/).

Create queue

Yii::$app->queue->queueCreate('test');

Purge queue

Yii::$app->queue->queuePurge('test');

Remove queue

Yii::$app->queue->queueRemove('test');

Create job

$data = [
    'someParam' => 'someValue',
];

$options = [
    'keepResult' => true,
    'keepResultDuration' => 86400,
];

$job = Yii::$app->queue->jobCreate('test', SomeWorker::className(), $data, $options);

Pause job

Yii::$app->queue->jobPause($job->_id);

Resume job

Yii::$app->queue->jobResume($job->_id);

Remove job

Yii::$app->queue->jobRemove($job->_id);

Retry failed job

Yii::$app->queue->jobRetry($job->_id);

Get job data

Yii::$app->queue->jobStatus($job->_id);

Spawn worker and bind it to all queues

./yii q/spawn

Spawn 3 workers and bind them to queues download and report

./yii q/spawn 3 download,report

Remove dead workers which processes are not found at this host

./yii q/remove-dead-workers

Remove stale jobs which keepResultDuration is passed

./yii q/remove-stale-jobs

Stop workers bound to queues download and report

./yii q/stop-workers download,report

Stop workers bound to all queues (notice how it differs from stopping all workers)

./yii q/stop-workers

Stop all workers

./yii q/stop-all-workers

GUI

GUI can be accessed at http://your.project.com/q.