-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new command for emptying queus in RabbitMq and MySql #853
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7e03d70
Add new command for emptying queus in RabbitMq and MySql
ugljesaspx 26ee8cc
Clear code
ugljesaspx f733ad9
Formatting
ugljesaspx a9f269a
Formatting Code
ugljesaspx af54526
Formatting Code
ugljesaspx 378dc83
Formatting Code
ugljesaspx d2f8f9a
Tidying code, clearing only rabbitmq queues
ugljesaspx 570a839
Remove unused variable
ugljesaspx f23fdcf
Fixing for CI
ugljesaspx f7c2eca
Use Magento\Framework\MessageQueue to clear message queues
supercid 43bc665
Merge remote-tracking branch 'origin/develop' into spx_ssp_55
supercid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?php | ||
|
||
namespace Nosto\Tagging\Console\Command; | ||
|
||
use Magento\Framework\Exception\LocalizedException; | ||
use Magento\Framework\MessageQueue\Consumer\ConfigInterface as ConsumerConfig; | ||
use Magento\Framework\MessageQueue\QueueRepository; | ||
use RuntimeException; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class NostoClearQueueCommand extends Command | ||
{ | ||
/** | ||
* Nosto Product Sync Update label. | ||
* | ||
* @var string | ||
*/ | ||
public const NOSTO_UPDATE_SYNC_MESSAGE_QUEUE = 'nosto_product_sync.update'; | ||
|
||
/** | ||
* Nosto Product Sync Delete label. | ||
* | ||
* @var string | ||
*/ | ||
public const NOSTO_DELETE_MESSAGE_QUEUE = 'nosto_product_sync.delete'; | ||
|
||
/** | ||
* @var ConsumerConfig | ||
*/ | ||
private $consumerConfig; | ||
|
||
/** | ||
* @var QueueRepository | ||
*/ | ||
private $queueRepository; | ||
|
||
private array $consumers = [ | ||
self::NOSTO_DELETE_MESSAGE_QUEUE, | ||
self::NOSTO_UPDATE_SYNC_MESSAGE_QUEUE, | ||
]; | ||
|
||
/** | ||
* NostoClearQueueCommand constructor. | ||
* | ||
* @param ConsumerConfig $consumerConfig | ||
* @param QueueRepository $queueRepository | ||
*/ | ||
public function __construct( | ||
ConsumerConfig $consumerConfig, | ||
QueueRepository $queueRepository | ||
) { | ||
$this->consumerConfig = $consumerConfig; | ||
$this->queueRepository = $queueRepository; | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Configure the command and the arguments | ||
*/ | ||
protected function configure() | ||
{ | ||
$this->setName('nosto:clear:message-queue') | ||
->setDescription('Clear all message queues for Nosto product sync topics.'); | ||
parent::configure(); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$io = new SymfonyStyle($input, $output); | ||
|
||
try { | ||
foreach ($this->consumers as $queueName) { | ||
$this->clearQueue($io, $queueName); | ||
} | ||
$io->success('Successfully cleared message queues.'); | ||
} catch (RuntimeException|LocalizedException $e) { | ||
$io->error('An error occurred while clearing message queues: ' . $e->getMessage()); | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
|
||
/** | ||
* Clear message queues by consumer name. | ||
* | ||
* @param SymfonyStyle $io | ||
* @param string $consumerName | ||
* @return void | ||
* @throws LocalizedException | ||
*/ | ||
private function clearQueue(SymfonyStyle $io, string $consumerName): void | ||
{ | ||
$io->writeln(sprintf('Clearing messages from %s', $consumerName)); | ||
$io->createProgressBar(); | ||
$io->progressStart(); | ||
$consumerConfig = $this->consumerConfig->getConsumer($consumerName); | ||
$queue = $this->queueRepository->get($consumerConfig->getConnection(), $consumerConfig->getQueue()); | ||
while ($message = $queue->dequeue()) { | ||
$io->progressAdvance(1); | ||
$queue->acknowledge($message); | ||
} | ||
$io->progressFinish(); | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing a check if
Magento_AsynchronousOperations
is installed, see this example: https://github.com/Nosto/nosto-magento2/blob/develop/Model/Service/Sync/AbstractBulkPublisher.php#L164