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 mixed actionPurge ( ) |
public function actionPurge()
{
$this->queue->purge();
}
Runs all jobs from db-queue.
It can be used as cron job.
| public mixed 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 mixed actionRunLoop ( integer $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 mixed 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);
}
}