8000 Add support for RecoverableException · symfony/symfony@654b197 · GitHub
[go: up one dir, main page]

Skip to content

Commit 654b197

Browse files
committed
Add support for RecoverableException
1 parent 39aab26 commit 654b197

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed

src/Symfony/Component/Messenger/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ CHANGELOG
88
* Moved Doctrine transport to package `symfony/doctrine-messenger`. All classes in `Symfony\Component\Messenger\Transport\Doctrine` have been moved to `Symfony\Component\Messenger\Bridge\Doctrine\Transport`
99
* Moved RedisExt transport to package `symfony/redis-messenger`. All classes in `Symfony\Component\Messenger\Transport\RedisExt` have been moved to `Symfony\Component\Messenger\Bridge\Redis\Transport`
1010
* Added support for passing a `\Throwable` argument to `RetryStrategyInterface` methods. This allows to define strategies based on the reason of the handling failure.
11-
* Added `StopWorkerOnFailureLimitListener` to stop the worker after a specified amount of failed messages is reached.
11+
* Added `StopWorkerOnFailureLimitListener` to stop the worker after a specified amount of failed messages is reached.
12+
* Added `RecoverableExceptionInterface` interface to force retry.
1213

1314
5.0.0
1415
-----

src/Symfony/Component/Messenger/EventListener/SendFailedMessageForRetryListener.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Messenger\Envelope;
1717
use Symfony\Component\Messenger\Event\WorkerMessageFailedEvent;
1818
use Symfony\Component\Messenger\Exception\HandlerFailedException;
19+
use Symfony\Component\Messenger\Exception\RecoverableExceptionInterface;
1920
use Symfony\Component\Messenger\Exception\RuntimeException;
2021
use Symfony\Component\Messenger\Exception\UnrecoverableExceptionInterface;
2122
use Symfony\Component\Messenger\Retry\RetryStrategyInterface;
@@ -87,6 +88,10 @@ public static function getSubscribedEvents()
8788

8889
private function shouldRetry(\Throwable $e, Envelope $envelope, RetryStrategyInterface $retryStrategy): bool
8990
{
91+
if ($e instanceof RecoverableExceptionInterface) {
92+
return true;
93+
}
94+
9095
// if ALL nested Exceptions are an instance of UnrecoverableExceptionInterface we should not retry
9196
if ($e instanceof HandlerFailedException) {
9297
$shouldNotRetry = true;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Messenger\Exception;
13+
14+
/**
15+
* Marker interface for exceptions to indicate that handling a message should have worked.
16+
*
17+
* If something goes wrong while handling a message that's received from a transport
18+
* and the message should must be retried, a handler can throw such an exception.
19+
*
20+
* @author Jérémy Derussé <jeremy@derusse.com>
21+
*/
22+
interface RecoverableExceptionInterface extends \Throwable
23+
{
24+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Messenger\Exception;
13+
14+
/**
15+
* A concrete implementation of RecoverableExceptionInterface that can be used directly.
16+
*
17+
* @author Frederic Bouchery <frederic@bouchery.fr>
18+
*/
19+
class RecoverableMessageHandlingException extends RuntimeException implements RecoverableExceptionInterface
20+
{
21+
}

0 commit comments

Comments
 (0)
0