forked from mpoiriert/draw
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
29d2fb5
commit 94bffd2
Showing
12 changed files
with
173 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
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 | ||
{ | ||
private ?MessengerMessage $message; | ||
|
||
public function __construct( | ||
MessengerMessage $message, | ||
) { | ||
$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 | ||
{ | ||
return ['message']; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
packages/messenger/MessageHandler/RetryFailedMessageMessageHandler.php
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,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Draw\Component\Messenger\MessageHandler; | ||
|
||
use Draw\Component\Messenger\Message\RetryFailedMessageMessage; | ||
use Symfony\Bundle\FrameworkBundle\Console\Application; | ||
use Symfony\Component\Console\Input\ArrayInput; | ||
use Symfony\Component\Console\Output\NullOutput; | ||
use Symfony\Component\HttpKernel\KernelInterface; | ||
use Symfony\Component\Messenger\Attribute\AsMessageHandler; | ||
|
||
class RetryFailedMessageMessageHandler | ||
{ | ||
public function __construct( | ||
private KernelInterface $kernel, | ||
) { | ||
} | ||
|
||
#[AsMessageHandler] | ||
public function handleRetryFailedMessageMessage(RetryFailedMessageMessage $message): void | ||
{ | ||
$application = new Application($this->kernel); | ||
$application->setAutoExit(false); | ||
|
||
$application->run( | ||
new ArrayInput( | ||
[ | ||
'command' => 'messenger:failed:retry', | ||
'id' => [ | ||
$message->getMessage()->getId(), | ||
], | ||
'--force' => true, | ||
] | ||
), | ||
new NullOutput() | ||
); | ||
} | ||
} |
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
38 changes: 38 additions & 0 deletions
38
packages/sonata-integration-bundle/Messenger/Controller/MessageController.php
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,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Draw\Bundle\SonataIntegrationBundle\Messenger\Controller; | ||
|
||
use App\Entity\MessengerMessage; | ||
use Draw\Component\Messenger\Message\RetryFailedMessageMessage; | ||
use Sonata\AdminBundle\Controller\CRUDController; | ||
use Symfony\Component\Messenger\MessageBusInterface; | ||
|
||
class MessageController extends CRUDController | ||
{ | ||
public function retryAction( | ||
MessengerMessage $message, | ||
MessageBusInterface $messageBus | ||
) { | ||
if ('failed' !== $message->getQueueName()) { | ||
$this->addFlash( | ||
'sonata_flash_error', | ||
$this->trans('message_cannot_be_retried') | ||
); | ||
|
||
return $this->redirectToList(); | ||
} | ||
|
||
$messageBus->dispatch( | ||
new RetryFailedMessageMessage($message) | ||
); | ||
|
||
$this->addFlash( | ||
'sonata_flash_success', | ||
$this->trans('retry_message_successfully_dispatched') | ||
); | ||
|
||
return $this->redirectToList(); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
packages/sonata-integration-bundle/Resources/translations/DrawMessengerAdmin.en.yaml
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,2 @@ | ||
message_cannot_be_retried: Message cannot be retried. | ||
retry_message_successfully_dispatched: Retry message successfully dispatched. |
8 changes: 8 additions & 0 deletions
8
.../sonata-integration-bundle/Resources/views/Messenger/Message/list__action_retry.html.twig
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,8 @@ | ||
{% if 'failed' == object.getQueueName() %} | ||
<a href="{{ admin.generateObjectUrl('retry', object) }}" | ||
class="btn btn-sm btn-default" | ||
title="Retry" | ||
> | ||
<i class="fa fa-rotate-right"></i> Retry | ||
</a> | ||
{% endif %} |
8 changes: 8 additions & 0 deletions
8
.../sonata-integration-bundle/Resources/views/Messenger/Message/show__action_retry.html.twig
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,8 @@ | ||
<li> | ||
<a class="sonata-action-element" | ||
href="{{ admin.generateObjectUrl('retry', object ) }}" | ||
title="Retry" | ||
> | ||
<i class="fa fa-rotate-right"></i> Retry | ||
</a> | ||
</li> |
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