Class zhuravljov\yii\queue\redis\Command
Inheritance | zhuravljov\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 Properties
Property | Type | Description | Defined By |
---|---|---|---|
$queue | zhuravljov\yii\queue\Queue | zhuravljov\yii\queue\redis\Command |
Public 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
Method Details
Purges the redis-queue.
public void actionPurge ( ) |
public function actionPurge()
{
$this->queue->purge();
}
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);
}
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);
}
}
}
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);
}
}