Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Allow to process messages from different channels * Add "maximum" option to the "run" console command * Improve messages * Fix test * Apply fixes from StyleCI * Fix typecasting bug --------- Co-authored-by: StyleCI Bot <bot@styleci.io>
- Loading branch information
1 parent
8498f59
commit 9ce1388
Showing
9 changed files
with
52 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,16 +7,17 @@ | |
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Yiisoft\Queue\QueueFactory; | ||
use Yiisoft\Queue\QueueFactoryInterface; | ||
|
||
final class RunCommand extends Command | ||
{ | ||
protected static $defaultName = 'queue:run'; | ||
protected static $defaultDescription = 'Runs all the existing messages in the queue. Exits once messages are over.'; | ||
protected static $defaultDescription = 'Runs all the existing messages in the given queues. ' . | ||
'Exits once messages are over.'; | ||
|
||
public function __construct(private QueueFactoryInterface $queueFactory) | ||
public function __construct(private QueueFactoryInterface $queueFactory, private array $channels) | ||
{ | ||
parent::__construct(); | ||
} | ||
|
@@ -25,17 +26,31 @@ public function configure(): void | |
{ | ||
$this->addArgument( | ||
'channel', | ||
InputArgument::OPTIONAL, | ||
'Queue channel name to connect to', | ||
QueueFactory::DEFAULT_CHANNEL_NAME | ||
); | ||
InputArgument::OPTIONAL | InputArgument::IS_ARRAY, | ||
'Queue channel name list to connect to.', | ||
$this->channels, | ||
) | ||
->addOption( | ||
'maximum', | ||
'm', | ||
InputOption::VALUE_REQUIRED, | ||
'Maximum number of messages to process in each channel. Default is 0 (no limits).', | ||
0, | ||
Check warning on line 38 in src/Command/RunCommand.php GitHub Actions / mutation / PHP 8.0-ubuntu-latest
Check warning on line 38 in src/Command/RunCommand.php GitHub Actions / mutation / PHP 8.0-ubuntu-latest
|
||
) | ||
->addUsage('[channel1 [channel2 [...]]] --maximum 100'); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$this->queueFactory | ||
->get($input->getArgument('channel')) | ||
->run(); | ||
/** @var string $channel */ | ||
foreach ($input->getArgument('channel') as $channel) { | ||
$output->write("Processing channel $channel... "); | ||
Check warning on line 47 in src/Command/RunCommand.php GitHub Actions / mutation / PHP 8.0-ubuntu-latest
|
||
$count = $this->queueFactory | ||
->get($channel) | ||
->run((int)$input->getOption('maximum')); | ||
|
||
$output->writeln("Messages processed: $count."); | ||
Check warning on line 52 in src/Command/RunCommand.php GitHub Actions / mutation / PHP 8.0-ubuntu-latest
|
||
} | ||
|
||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters