WorkerCommand   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 7
dl 0
loc 25
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A actionWork() 0 7 1
A output() 0 4 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