2017 © Pedro Peláez
 

yii2-extension yii2-queue

Package base on yii2-queue with some improvements

image

mice-tm/yii2-queue

Package base on yii2-queue with some improvements

  • Monday, December 4, 2017
  • by mice-tm
  • Repository
  • 0 Watchers
  • 0 Stars
  • 253 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 4 Versions
  • 201 % Grown

The README.md

Yii2 Queue Extension

An extension for running tasks asyncronously via queues., (*1)

It supported queues based on DB, Redis, RabbitMQ, Beanstalk and Gearman., (*2)

Added delayed queue support for AMQP and health-checks for queues, (*3)

Fork of https://github.com/yiisoft/yii2-queue, (*4)

Installation

The preferred way to install this extension is through composer., (*5)

Update composer.json 1) add to the require section of your composer.json file,, (*6)

"mice-tm/yii2-queue": "dev-master"

2) then add a repositories section of your composer.json file., (*7)

{
  "type": "vcs",
  "url": "https://github.com/mice-tm/yii2-queue"
}

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:, (*8)

class DownloadJob extends Object implements \yii\queue\Job
{
    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:, (*9)

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:, (*10)

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., (*11)

Command that obtains and executes tasks in a loop until queue is empty:, (*12)

yii queue/run

Command launches a daemon which infinitely queries the queue:, (*13)

yii queue/listen

See documentation for more details about driver console commands and their options., (*14)

The component has ability to track status of a job which was pushed into queue., (*15)

// Push a job into queue and get massage 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);

The Versions

04/12 2017

dev-master

9999999-dev

Package base on yii2-queue with some improvements

  Sources   Download

MIT

The Requires

 

by Iryna Mychkova

yii2 queue amqp delayed queue

04/12 2017

0.1.0

0.1.0.0

Package base on yii2-queue with some improvements

  Sources   Download

MIT

The Requires

 

by Iryna Mychkova

yii2 queue amqp delayed queue

30/10 2017

0.0.2

0.0.2.0

Package base on yii2-queue with some improvements

  Sources   Download

MIT

The Requires

 

by Iryna Mychkova

yii2 queue amqp delayed queue

19/10 2017

0.0.1

0.0.1.0

Package base on yii2-queue with some improvements

  Sources   Download

MIT

The Requires

 

by Iryna Mychkova

yii2 queue amqp delayed queue