-
-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathRunCommand.php
More file actions
41 lines (34 loc) · 1.11 KB
/
RunCommand.php
File metadata and controls
41 lines (34 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
declare(strict_types=1);
namespace Yiisoft\Yii\Queue\Command;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Yiisoft\Yii\Queue\QueueFactory;
use Yiisoft\Yii\Queue\QueueFactoryInterface;
#[AsCommand('queue:run', 'Runs all the existing messages in the queue. Exits once messages are over.')]
final class RunCommand extends Command
{
public function __construct(private QueueFactoryInterface $queueFactory)
{
parent::__construct();
}
public function configure(): void
{
$this->addArgument(
'channel',
InputArgument::OPTIONAL,
'Queue channel name to connect to',
QueueFactory::DEFAULT_CHANNEL_NAME
);
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->queueFactory
->get($input->getArgument('channel'))
->run();
return 0;
}
}