Class zhuravljov\yii\queue\redis\Command

Inheritancezhuravljov\yii\queue\redis\Command » yii\console\Controller
Source Code https://github.com/yiisoft/yii2-queue/blob/master/src/redis/Command.php

Manages application redis-queue.

Public Methods

Hide inherited methods

Method Description Defined By
actionPurge() Purges the redis-queue. zhuravljov\yii\queue\redis\Command
actionRunAll() Runs all jobs from redis-queue. zhuravljov\yii\queue\redis\Command
actionRunLoop() Listens redis-queue and runs new jobs. zhuravljov\yii\queue\redis\Command
actionRunOne() Runs one job from redis-queue. zhuravljov\yii\queue\redis\Command

Property Details

Hide inherited properties

$queue public property

Method Details

Hide inherited methods

actionPurge() public method

Purges the redis-queue.

public void actionPurge ( )

                public function actionPurge()
{
    $this->queue->purge();
}

            
actionRunAll() public method

Runs all jobs from redis-queue.

It can be used as cron job.

public void actionRunAll ( )

                public function actionRunAll()
{
    $this->stdout("Worker has been started.\n", Console::FG_GREEN);
    $count = 0;
    while ($this->queue->work(false)) {
        $count++;
    }
    $this->stdout("$count jobs have been complete.\n", Console::FG_GREEN);
}

            
actionRunLoop() public method

Listens redis-queue and runs new jobs.

It can be used as demon process.

public void actionRunLoop ( $delay 3 )
$delay integer

Number of seconds for waiting new job.

                public function actionRunLoop($delay = 3)
{
    $this->stdout("Worker has been started.\n", Console::FG_GREEN);
    while (($run = $this->queue->work(false)) || !$delay || sleep($delay) === 0) {
        if ($run) {
            $this->stdout("Job has been complete.\n", Console::FG_GREEN);
        }
    }
}

            
actionRunOne() public method

Runs one job from redis-queue.

public void actionRunOne ( )

                public function actionRunOne()
{
    if ($this->queue->work(true)) {
        $this->stdout("Job has been complete.\n", Console::FG_GREEN);
    } else {
        $this->stdout("Job not found.\n", Console::FG_RED);
    }
}