yiisoft/yii2-queue Yii2 Queue Extension which supported DB, Redis, RabbitMQ, Beanstalk and Gearman

redisgiiqueuedbasyncrabbitmqgearmanbeanstalk

993323

Yii2 Queue Extension


An extension for running tasks asyncronously via queues.

It supported queues based on DB, Redis, RabbitMQ, Beanstalk and Gearman.

Documentation is at https://github.com/yiisoft/yii2-queue/blob/master/docs/guide/README.md.

Latest Stable Version Total Downloads Build Status

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist yiisoft/yii2-queue

or add

"yiisoft/yii2-queue": "~2.0.0"

to the require section of your composer.json file.

Basic Usage

Each task which is sent to queue should be defined as a separate class. For example, if you need to download and save a file the class may look like the following:

class DownloadJob extends BaseObject implements \yii\queue\JobInterface
{
    public $url;
    public $file;

    public function execute($queue)
    {
        file_put_contents($this->file, file_get_contents($this->url));
    }
}

Here's how to send a task into queue:

Yii::$app->queue->push(new DownloadJob([
    'url' => 'http://example.com/image.jpg',
    'file' => '/tmp/image.jpg',
]));

Pushes job into queue that run after 5 min:

Yii::$app->queue->delay(5 * 60)->push(new DownloadJob([
    'url' => 'http://example.com/image.jpg',
    'file' => '/tmp/image.jpg',
]));

The exact way task is executed depends on the driver used. The most part of drivers can be run using console commands, which the component registers in your application.

Command that obtains and executes tasks in a loop until queue is empty:

yii queue/run

Command launches a daemon which infinitely queries the queue:

yii queue/listen

See documentation for more details about driver console commands and their options.

The component has ability to track status of a job which was pushed into queue.

// Push a job into queue and get message ID.
$id = Yii::$app->queue->push(new SomeJob());

// The job is waiting for execute.
Yii::$app->queue->isWaiting($id);

// Worker gets the job from queue, and executing it.
Yii::$app->queue->isReserved($id);

// Worker has executed the job.
Yii::$app->queue->isDone($id);

For more details see the guide.

Changelog

Yii2 Queue Extension Change Log

2.0.2 under development

  • no changes in this release.

2.0.1, November 13, 2017

  • Bug #98: Fixed timeout error handler (zhuravljov)
  • Bug #112: Queue command inside module (tsingsun)
  • Bug #118: Synchronized moving of delayed and reserved jobs to waiting list (zhuravljov)
  • Bug #155: Slave DB breaks listener (zhuravljov)
  • Enh #97: Queue::status is public method (zhuravljov)
  • Enh #116: Add Chinese Guide (kids-return)
  • Enh #122: Rename Job to JobInterface (zhuravljov)
  • Enh #137: All throwable errors caused by jobs are now caught (brandonkelly)
  • Enh #141: Clear and remove commands for File, DB, Beanstalk and Redis drivers (zhuravljov)
  • Enh #147: Igbinary job serializer (xutl)
  • Enh #148: Allow to change vhost setting for RabbitMQ (ischenko)
  • Enh #151: Compatibility with Yii 2.0.13 and PHP 7.2 (zhuravljov)
  • Enh #160: Benchmark of job wait time (zhuravljov)
  • Enh: Rename cli\Verbose behavior to cli\VerboseBehavior (zhuravljov)
  • Enh: Rename serializers\Serializer interface to serializers\SerializerInterface (zhuravljov)
  • Enh: Added Signal::setExitFlag() to stop Queue::run() loop manually (silverfire)

2.0.0

  • Enh: The package is moved to yiisoft/yii2-queue (zhuravljov)

1.1.0

  • Enh #50 Documentation about worker starting control (zhuravljov)
  • Enh #70: Durability for rabbitmq queues (mkubenka)
  • Enh: Detailed error about job type in message handling (zhuravljov)
  • Enh #60: Enhanced event handling (zhuravljov)
  • Enh: Job priority for DB driver (zhuravljov)
  • Enh: File mode options of file driver (zhuravljov)
  • Enh #47: Redis queue listen timeout (zhuravljov)
  • Enh #23: Retryable jobs (zhuravljov)

1.0.1

  • Enh #58: Deleting failed jobs from queue (zhuravljov)
  • Enh #55: Job priority (zhuravljov)

1.0.0

  • Enh: Improvements of log behavior (zhuravljov)
  • Enh: File driver stat info (zhuravljov)
  • Enh: Beanstalk stat info (zhuravljov)
  • Enh: Colorized driver info actions (zhuravljov)
  • Enh: Colorized verbose mode (zhuravljov)
  • Enh: Improvements of debug panel (zhuravljov)
  • Enh: Queue job message statuses (zhuravljov)
  • Enh: Gii job generator (zhuravljov)
  • Enh: Enhanced gearman driver (zhuravljov)
  • Enh: Queue message identifiers (zhuravljov)
  • Enh: File queue (zhuravljov)

0.12.2

  • Enh #10: Separate option that turn off isolate mode of job execute (zhuravljov)

0.12.1

  • Bug #37: Fixed opening of a child process (zhuravljov)
  • Enh: Ability to push a closure (zhuravljov)
  • Enh: Before push event (zhuravljov)

0.12.0

  • Enh #18: Executes a job in a child process (zhuravljov)
  • Bug #25: Enabled output buffer breaks output streams (luke-)
  • Enh: After push event (zhuravljov)

0.11.0

  • Enh #21: Delayed jobs for redis queue (zhuravljov)
  • Enh: Info action for db and redis queue command (zhuravljov)

0.10.1

  • Bug: Fixed db driver for pgsql (zhuravljov)
  • Bug #16: Timeout of  queue reading lock for db driver (zhuravljov)
  • Enh: Minor code style enhancements (SilverFire)

0.10.0

  • Enh #14: Json job serializer (zhuravljov)
  • Enh: Delayed running of a job (zhuravljov)

0.9.1

  • Bug #13: Fixed reading of DB queue (zhuravljov)

0.9.0

  • Enh: Signal handlers (zhuravljov)
  • Enh: Add exchange for AMQP driver (airani)
  • Enh: Beanstalk driver (zhuravljov)
  • Enh: Added English docs (samdark)

Statistics

Downloads
GitHub Stars
GitHub Forks

Releases

Comments



2.0.1 is the latest of 26 releases



BSD-3-Clause license
Stats
503 github stars & 107 github forks
0 downloads in the last day
13147 downloads in the last 30 days
40063 total downloads