File tree Expand file tree Collapse file tree 2 files changed +16
-13
lines changed
transactionoutbox-core/src/main/java/com/gruelbox/transactionoutbox Expand file tree Collapse file tree 2 files changed +16
-13
lines changed Original file line number Diff line number Diff line change 4
4
5
5
/**
6
6
* Defines a custom retry policy for tasks scheduled in the {@link TransactionOutbox}.
7
- * <p>
8
- * Implement this interface in the class that is passed to
9
- * {@link TransactionOutbox#schedule(Class)} to override the default retry behavior.
10
- * </p>
7
+ *
8
+ * <p>Implement this interface in the class that is passed to {@link
9
+ * TransactionOutbox#schedule(Class)} to override the default retry behavior.
11
10
*/
12
11
public interface RetryPolicyAware {
13
12
/**
14
13
* Determines the wait duration before retrying a failed task.
15
14
*
16
- * @param attempt The current retry attempt (starting from 1).
15
+ * @param attempt The current retry attempt (starting from 1).
17
16
* @param throwable The exception that caused the failure.
18
17
* @return The duration to wait before the next retry.
19
18
*/
@@ -22,10 +21,10 @@ public interface RetryPolicyAware {
22
21
/**
23
22
* Specifies the maximum number of retry attempts before blocking the task.
24
23
*
25
- * @param attempt The current retry attempt (starting from 1).
24
+ * @param attempt The current retry attempt (starting from 1).
26
25
* @param throwable The exception that caused the failure.
27
- * @return The number of attempts after which the task should be blocked.
28
- * If the returned value is less than or equal to {@code attempt}, the task is blocked immediately.
26
+ * @return The number of attempts after which the task should be blocked. If the returned value is
27
+ * less than or equal to {@code attempt}, the task is blocked immediately.
29
28
*/
30
29
int blockAfterAttempts (int attempt , Throwable throwable );
31
30
}
Original file line number Diff line number Diff line change @@ -389,18 +389,22 @@ private Instant after(Duration duration) {
389
389
}
390
390
391
391
private void updateAttemptCount (
392
- TransactionOutboxEntry entry , Throwable cause , RetryPolicyAware work ) {
392
+ TransactionOutboxEntry entry , Throwable cause , RetryPolicyAware retryPolicyAware ) {
393
393
try {
394
394
entry .setAttempts (entry .getAttempts () + 1 );
395
395
396
396
int blockAfterAttempts =
397
- work == null
397
+ retryPolicyAware == null
398
398
? this .blockAfterAttempts
399
- : work .blockAfterAttempts (entry .getAttempts (), cause );
399
+ : retryPolicyAware .blockAfterAttempts (entry .getAttempts (), cause );
400
400
Duration waitDuration =
401
- work == null ? this .attemptFrequency : work .waitDuration (entry .getAttempts (), cause );
401
+ retryPolicyAware == null
402
+ ? this .attemptFrequency
403
+ : retryPolicyAware .waitDuration (entry .getAttempts (), cause );
402
404
403
- var blocked = (entry .getTopic () == null ) && (entry .getAttempts () >= blockAfterAttempts );
405
+ var blocked =
406
+ (entry .getTopic () == null || retryPolicyAware != null )
407
+ && (entry .getAttempts () >= blockAfterAttempts );
404
408
entry .setBlocked (blocked );
405
409
transactionManager .inTransactionThrows (tx -> pushBack (tx , entry , waitDuration ));
406
410
listener .failure (entry , cause );
You can’t perform that action at this time.
0 commit comments