Completed
Push — master ( 96e614...1e74ba )
by Vladimir
03:46
created

QueueWorker   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 34
c 0
b 0
f 0
rs 10
wmc 3
lcom 1
cbo 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 6 1
A handle() 0 19 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Toolbelt\Commands;
6
7
use FondBot\Contracts\Queue;
8
use FondBot\Toolbelt\Command;
9
10
class QueueWorker extends Command
11
{
12
    protected function configure(): void
13
    {
14
        $this
15
            ->setName('queue:worker')
16
            ->setDescription('Run queue worker');
17
    }
18
19
    /**
20
     * Handle command.
21
     *
22
     * @throws \Psr\Container\ContainerExceptionInterface
23
     */
24
    public function handle(): void
25
    {
26
        /** @var Queue $queue */
27
        $queue = $this->kernel->resolve(Queue::class);
28
        $queue->connect();
29
30
        $this->info('Worker started...');
31
32
        while (true) {
33
            $job = $queue->next();
34
35
            $this->line('Job: '.get_class($job));
36
37
            $driver = $job->driver;
38
            $command = $job->command;
39
40
            $driver->handle($command);
41
        }
42
    }
43
}
44