Class zhuravljov\yii\queue\db\Command
Inheritance | zhuravljov\yii\queue\db\Command » yii\console\Controller |
---|---|
Source Code | https://github.com/yiisoft/yii2-queue/blob/master/src/db/Command.php |
Manages application db-queue.
Public Properties
Property | Type | Description | Defined By |
---|---|---|---|
$queue | zhuravljov\yii\queue\Queue | zhuravljov\yii\queue\db\Command |
Public Methods
Method | Description | Defined By |
---|---|---|
actionPurge() | Purges the db-queue. | zhuravljov\yii\queue\db\Command |
actionRunAll() | Runs all jobs from db-queue. | zhuravljov\yii\queue\db\Command |
actionRunLoop() | Listens db-queue and runs new jobs. | zhuravljov\yii\queue\db\Command |
actionRunOne() | Runs one job from db-queue. | zhuravljov\yii\queue\db\Command |
Property Details
Method Details
Purges the db-queue.
public void actionPurge ( ) |
public function actionPurge()
{
$this->queue->purge();
}
Runs all jobs from db-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 db-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 db-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);
}
}