JobQueueCommand::worker()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
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