Skip to content

Commit

Permalink
Merge branch 'main' into do_not_return_full_html_page
Browse files Browse the repository at this point in the history
  • Loading branch information
melroy89 authored Sep 19, 2024
2 parents 01db78f + 754eb91 commit 4c81dc8
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
8 changes: 8 additions & 0 deletions docs/02-admin/04-running-mbin/messenger.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,11 @@ We have a few different queues:
9. `dead` [PostgreSQL]: dead jobs that will not be retried

We need the `dead` queue so that messages that throw a `UnrecoverableMessageHandlingException`, which is used to indicate that a message should not be retried and go straight to the supplied failure queue

## Remove failed messages

We created a simple command to clean-up all the failed messages from the database at once:

```bash
./bin/console mbin:messenger:failed:remove_all
```
49 changes: 49 additions & 0 deletions src/Command/RemoveFailedMessagesCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

namespace App\Command;

use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

#[AsCommand(
name: 'mbin:messenger:failed:remove_all',
description: 'This command removes all failed messages from the failed queue (database).',
)]
class RemoveFailedMessagesCommand extends Command
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
) {
parent::__construct();
}

protected function configure(): void
{
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);

$this->removeFailedMessages();

return Command::SUCCESS;
}

/**
* Remove all failed messages from database.
*/
private function removeFailedMessages()
{
$this->entityManager->getConnection()->executeQuery(
'DELETE FROM messenger_messages WHERE queue_name = ?',
['failed']
);
}
}

0 comments on commit 4c81dc8

Please sign in to comment.