WorkerCommand::output()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace yiicod\jobqueue\commands;
4
5
use Illuminate\Queue\WorkerOptions;
6
use Yii;
7
use yii\console\Controller;
8
use yiicod\jobqueue\failed\MongoFailedJobProvider;
9
use yiicod\jobqueue\handlers\ExceptionHandler;
10
use yiicod\jobqueue\Worker;
11
12
class WorkerCommand extends Controller
13
{
14
    use CommandTrait;
15
16
    /**
17
     * @var string
18
     */
19
    public $defaultAction = 'work';
20
21
    /**
22
     * @throws \Exception
23
     */
24
    public function actionWork()
25
    {
26
        $queueManager = Yii::$app->jobqueue->getQueueManager();
27
28
        $worker = new Worker($queueManager, new MongoFailedJobProvider(Yii::$app->mongodb, 'yii_jobs_failed'), new ExceptionHandler());
29
        $worker->daemon($this->connection, $this->queue, new WorkerOptions($this->delay, $this->memory, $this->timeout, $this->sleep, $this->maxTries));
30
    }
31
32
    protected function output($text)
33
    {
34
        $this->stdout($text);
35
    }
36
}
37