-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new command: "Remove failed messages command" (#1132)
- Loading branch information
Showing
1 changed file
with
49 additions
and
0 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
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'] | ||
); | ||
} | ||
} |