1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Yii\Queue\Command; |
6
|
|
|
|
7
|
|
|
use Symfony\Component\Console\Command\Command; |
8
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
10
|
|
|
use Symfony\Component\Console\Input\InputOption; |
11
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
12
|
|
|
use Yiisoft\Yii\Console\ExitCode; |
|
|
|
|
13
|
|
|
use Yiisoft\Yii\Queue\Cli\LoopInterface; |
|
|
|
|
14
|
|
|
use Yiisoft\Yii\Queue\QueueFactoryInterface; |
|
|
|
|
15
|
|
|
|
16
|
|
|
final class ListenAllCommand extends Command |
17
|
|
|
{ |
18
|
|
|
protected static $defaultName = 'queue:listen-all'; |
19
|
|
|
protected static $defaultDescription = 'Listens the all the given queues and executes messages as they come. ' . |
20
|
|
|
'Meant to be used in development environment only. ' . |
21
|
|
|
'Listens all configured queues by default in case you\'re using yiisoft/config. ' . |
22
|
|
|
'Needs to be stopped manually.'; |
23
|
|
|
|
24
|
|
|
private QueueFactoryInterface $queueFactory; |
25
|
|
|
private LoopInterface $loop; |
26
|
|
|
|
27
|
|
|
public function __construct(QueueFactoryInterface $queueFactory, LoopInterface $loop, private array $channels) |
28
|
|
|
{ |
29
|
|
|
parent::__construct(); |
30
|
|
|
|
31
|
|
|
$this->queueFactory = $queueFactory; |
32
|
|
|
$this->loop = $loop; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function configure(): void |
36
|
|
|
{ |
37
|
|
|
$this->addArgument( |
38
|
|
|
'channel', |
39
|
|
|
InputArgument::OPTIONAL | InputArgument::IS_ARRAY, |
40
|
|
|
'Queue channel name list to connect to', |
41
|
|
|
$this->channels, |
42
|
|
|
) |
43
|
|
|
->addOption( |
44
|
|
|
'pause', |
45
|
|
|
'p', |
46
|
|
|
InputOption::VALUE_REQUIRED, |
47
|
|
|
'Pause between queue channel iterations in seconds. May save some CPU. Default: 1', |
48
|
|
|
1, |
49
|
|
|
) |
50
|
|
|
->addOption( |
51
|
|
|
'maximum', |
52
|
|
|
'm', |
53
|
|
|
InputOption::VALUE_REQUIRED, |
54
|
|
|
'Maximum number of messages to process in each channel before switching to another channel. ' . |
55
|
|
|
'Default is 0 (no limits).', |
56
|
|
|
0, |
57
|
|
|
); |
58
|
|
|
|
59
|
|
|
$this->addUsage('[channel1 [channel2 [...]]] [--timeout=<timeout>] [--maximum=<maximum>]'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
63
|
|
|
{ |
64
|
|
|
$queues = []; |
65
|
|
|
/** @var string $channel */ |
66
|
|
|
foreach ($input->getArgument('channel') as $channel) { |
67
|
|
|
$queues[] = $this->queueFactory->get($channel); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
while ($this->loop->canContinue()) { |
71
|
|
|
$hasMessages = false; |
72
|
|
|
foreach ($queues as $queue) { |
73
|
|
|
$hasMessages = $queue->run((int)$input->getOption('maximum')) > 0 || $hasMessages; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
if (!$hasMessages) { |
77
|
|
|
sleep((int)$input->getOption('pause')); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return ExitCode::OK; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
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