RunCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 19
c 1
b 0
f 0
dl 0
loc 34
ccs 0
cts 26
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 16 4
A configure() 0 11 1
1
<?php
2
3
namespace Tarantool\JobQueue\Console\Command;
4
5
use Symfony\Component\Console\Input\InputInterface;
6
use Symfony\Component\Console\Input\InputOption;
7
use Symfony\Component\Console\Output\OutputInterface;
8
9
class RunCommand extends Command
10
{
11
    private const DEFAULT_IDLE_TIMEOUT = 1;
12
13
    protected function configure(): void
14
    {
15
        parent::configure();
16
17
        $this
18
            ->setName('run')
19
            ->setDescription('Runs a job worker')
20
            ->addOption('executors-config', 'e', InputOption::VALUE_REQUIRED)
21
            ->addOption('idle-timeout', 'i', InputOption::VALUE_REQUIRED, '', self::DEFAULT_IDLE_TIMEOUT)
22
            ->addOption('log-file', 'f', InputOption::VALUE_REQUIRED)
23
            ->addOption('log-level', 'l', InputOption::VALUE_REQUIRED)
24
        ;
25
    }
26
27
    protected function execute(InputInterface $input, OutputInterface $output): void
28
    {
29
        $configFactory = $this->createConfigFactory($input, $output);
30
31
        if ($logFile = $input->getOption('log-file')) {
32
            $configFactory->setLogFile($logFile);
33
        }
34
        if ($logLevel = $input->getOption('log-level')) {
35
            $configFactory->setLogLevel($logLevel);
36
        }
37
        if ($executorsConfigFile = $input->getOption('executors-config')) {
38
            $configFactory->setExecutorsConfigFile(realpath($executorsConfigFile));
39
        }
40
41
        $runner = $configFactory->createRunner();
42
        $runner->run($input->getOption('idle-timeout'));
43
    }
44
}
45