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
|
|
|
|