From e2485883aaeee4cf064d59f15e0434c65366c181 Mon Sep 17 00:00:00 2001 From: Adrian Dumitrache Date: Sat, 4 May 2024 12:39:52 +0300 Subject: [PATCH] Fix RetryFailedMessageMessage --- .../Message/RetryFailedMessageMessage.php | 24 ++++--------------- .../RetryFailedMessageMessageHandler.php | 2 +- .../RetryFailedMessageMessageHandlerTest.php | 5 +--- .../Controller/MessageController.php | 2 +- 4 files changed, 7 insertions(+), 26 deletions(-) diff --git a/packages/messenger/Message/RetryFailedMessageMessage.php b/packages/messenger/Message/RetryFailedMessageMessage.php index 6d703c45..eda4a8e3 100644 --- a/packages/messenger/Message/RetryFailedMessageMessage.php +++ b/packages/messenger/Message/RetryFailedMessageMessage.php @@ -4,31 +4,15 @@ namespace Draw\Component\Messenger\Message; -use App\Entity\MessengerMessage; -use Draw\Component\Messenger\DoctrineEnvelopeEntityReference\Message\DoctrineReferenceAwareInterface; -use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException; - -class RetryFailedMessageMessage implements DoctrineReferenceAwareInterface +class RetryFailedMessageMessage { - private ?MessengerMessage $message; - public function __construct( - MessengerMessage $message, + private string $messageId, ) { - $this->message = $message; - } - - public function getMessage(): MessengerMessage - { - if (null === $this->message) { - throw new UnrecoverableMessageHandlingException('Message is not set.'); - } - - return $this->message; } - public function getPropertiesWithDoctrineObject(): array + public function getMessageId(): string { - return ['message']; + return $this->messageId; } } diff --git a/packages/messenger/MessageHandler/RetryFailedMessageMessageHandler.php b/packages/messenger/MessageHandler/RetryFailedMessageMessageHandler.php index d10bb8a6..6e736f2a 100644 --- a/packages/messenger/MessageHandler/RetryFailedMessageMessageHandler.php +++ b/packages/messenger/MessageHandler/RetryFailedMessageMessageHandler.php @@ -24,7 +24,7 @@ public function handleRetryFailedMessageMessage(RetryFailedMessageMessage $messa [ $this->consolePath, 'messenger:failed:retry', - $message->getMessage()->getId(), + $message->getMessageId(), '--force', ] ) diff --git a/packages/messenger/Tests/MessageHandler/RetryFailedMessageMessageHandlerTest.php b/packages/messenger/Tests/MessageHandler/RetryFailedMessageMessageHandlerTest.php index 9f272617..b315ba6e 100644 --- a/packages/messenger/Tests/MessageHandler/RetryFailedMessageMessageHandlerTest.php +++ b/packages/messenger/Tests/MessageHandler/RetryFailedMessageMessageHandlerTest.php @@ -4,7 +4,6 @@ namespace Draw\Component\Messenger\Tests\MessageHandler; -use App\Entity\MessengerMessage; use Draw\Component\Messenger\Message\RetryFailedMessageMessage; use Draw\Component\Messenger\MessageHandler\RetryFailedMessageMessageHandler; use Draw\Contracts\Process\ProcessFactoryInterface; @@ -56,9 +55,7 @@ public function testHandleRetryFailedMessageMessage(): void ->method('mustRun'); $this->handler->handleRetryFailedMessageMessage( - new RetryFailedMessageMessage( - (new MessengerMessage())->setId($messageId) - ) + new RetryFailedMessageMessage($messageId) ); } } diff --git a/packages/sonata-integration-bundle/Messenger/Controller/MessageController.php b/packages/sonata-integration-bundle/Messenger/Controller/MessageController.php index 57807afd..d57ae430 100644 --- a/packages/sonata-integration-bundle/Messenger/Controller/MessageController.php +++ b/packages/sonata-integration-bundle/Messenger/Controller/MessageController.php @@ -25,7 +25,7 @@ public function retryAction( } $messageBus->dispatch( - new RetryFailedMessageMessage($message) + new RetryFailedMessageMessage($message->getId()) ); $this->addFlash(