JobQueueCommand   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A daemonName() 0 4 1
A worker() 0 7 1
1
<?php
2
3
namespace yiicod\jobqueue\commands;
4
5
use Illuminate\Queue\WorkerOptions;
6
use Yii;
7
use yiicod\cron\commands\DaemonController;
8
use yiicod\jobqueue\failed\MongoFailedJobProvider;
9
use yiicod\jobqueue\handlers\ExceptionHandler;
10
use yiicod\jobqueue\Worker;
11
12
/**
13
 * Command to start worker
14
 *
15
 * @author Virchenko Maksim <[email protected]>
16
 */
17
class JobQueueCommand extends DaemonController
18
{
19
    use CommandTrait;
20
21
    /**
22
     * Get daemon name
23
     *
24
     * @return string
25
     */
26
    protected function daemonName(): string
27
    {
28
        return 'jobqueue-' . $this->queue . '-' . $this->connection;
29
    }
30
31
    /**
32
     * Run queue worker
33
     *
34
     * @author Virchenko Maksim <[email protected]>
35
     */
36
    protected function worker()
37
    {
38
        $queueManager = Yii::$app->jobqueue->getQueueManager();
39
40
        $worker = new Worker($queueManager, new MongoFailedJobProvider(Yii::$app->mongodb, 'yii_jobs_failed'), new ExceptionHandler());
41
        $worker->daemon($this->connection, $this->queue, new WorkerOptions($this->delay, $this->memory, $this->timeout, $this->sleep, $this->maxTries));
42
    }
43
}
44