|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the daikon-cqrs/boot project. |
|
4
|
|
|
* |
|
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
6
|
|
|
* file that was distributed with this source code. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Daikon\Boot\Console\Command; |
|
10
|
|
|
|
|
11
|
|
|
use Daikon\AsyncJob\Worker\WorkerInterface; |
|
12
|
|
|
use Daikon\AsyncJob\Worker\WorkerMap; |
|
13
|
|
|
use Symfony\Component\Console\Command\Command; |
|
|
|
|
|
|
14
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
15
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
16
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
17
|
|
|
use Symfony\Component\Console\Question\ChoiceQuestion; |
|
18
|
|
|
|
|
19
|
|
|
class RunWorker extends Command |
|
20
|
|
|
{ |
|
21
|
|
|
use DialogTrait; |
|
22
|
|
|
|
|
23
|
|
|
protected WorkerMap $workerMap; |
|
24
|
|
|
|
|
25
|
|
|
public function __construct(WorkerMap $workerMap) |
|
26
|
|
|
{ |
|
27
|
|
|
parent::__construct(); |
|
28
|
|
|
$this->workerMap = $workerMap; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
protected function configure(): void |
|
32
|
|
|
{ |
|
33
|
|
|
$this |
|
34
|
|
|
->setName('worker:run') |
|
35
|
|
|
->setDescription('Run an asynchronous job worker.') |
|
36
|
|
|
->addArgument( |
|
37
|
|
|
'queue', |
|
38
|
|
|
InputArgument::REQUIRED, |
|
39
|
|
|
'Name of the message queue from which to execute jobs.' |
|
40
|
|
|
) |
|
41
|
|
|
->addArgument( |
|
42
|
|
|
'worker', |
|
43
|
|
|
InputArgument::OPTIONAL, |
|
44
|
|
|
'Name of the worker from which to execute jobs.' |
|
45
|
|
|
); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
//@todo support running multiple queues |
|
49
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
|
50
|
|
|
{ |
|
51
|
|
|
if (!is_string($workerName = $input->getArgument('worker'))) { |
|
52
|
|
|
$workerName = $this->listWorkers($input, $output); |
|
53
|
|
|
} |
|
54
|
|
|
/** @var WorkerInterface $worker */ |
|
55
|
|
|
$worker = $this->workerMap->get($workerName); |
|
56
|
|
|
$worker->run(['queue' => $input->getArgument('queue')]); |
|
57
|
|
|
//@todo return int from worker |
|
58
|
|
|
return 0; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
protected function listWorkers(InputInterface $input, OutputInterface $output): string |
|
62
|
|
|
{ |
|
63
|
|
|
if (!count($this->workerMap)) { |
|
64
|
|
|
$output->writeln('<error>There are no workers available.</error>'); |
|
65
|
|
|
$output->writeln(''); |
|
66
|
|
|
exit; |
|
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
$helper = $this->getHelper('question'); |
|
70
|
|
|
$question = new ChoiceQuestion( |
|
71
|
|
|
'Please select a worker: ', |
|
72
|
|
|
$this->workerMap->keys() //@todo show workers with filtered by queue |
|
73
|
|
|
); |
|
74
|
|
|
|
|
75
|
|
|
return $helper->ask($input, $output, $question); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths