You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by "quantranhong1999 (via GitHub)" <gi...@apache.org> on 2023/02/28 02:41:00 UTC

[GitHub] [james-project] quantranhong1999 commented on a diff in pull request #1467: JAMES-3892 Allow configuring the count of retries in LocalDelivery

quantranhong1999 commented on code in PR #1467:
URL: https://github.com/apache/james-project/pull/1467#discussion_r1119517505


##########
server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/delivery/MailDispatcher.java:
##########
@@ -172,10 +182,14 @@ private List<MailAddress> deliver(Mail mail, MimeMessage message) {
     }
 
     private Mono<Void> storeMailWithRetry(Mail mail, MailAddress recipient) {
-       return Mono.from(mailStore.storeMail(recipient, mail))
-           .doOnError(error -> LOGGER.warn("Error While storing mail. This error will be retried.", error))
-           .retryWhen(Retry.backoff(RETRIES, FIRST_BACKOFF).maxBackoff(MAX_BACKOFF).scheduler(Schedulers.parallel()))
-           .then();
+        Mono<Void> operation = Mono.from(mailStore.storeMail(recipient, mail))
+            .doOnError(error -> LOGGER.warn("Error While storing mail. This error will be retried.", error));
+
+        return retries.map(count ->
+            operation
+                .retryWhen(Retry.backoff(count, FIRST_BACKOFF).maxBackoff(MAX_BACKOFF).scheduler(Schedulers.parallel()))
+                .then())
+            .orElse(operation);

Review Comment:
   I think with this code, even when we do not do a retry or there are no retries left, we still log "This error will be retried.". That could lead to misunderstanding while observing.
   
   I propose to count the remaining retry count:
   ```java
           AtomicInteger remainRetries = new AtomicInteger(retries.orElse(0));
   
           Mono<Void> operation = Mono.from(mailStore.storeMail(recipient, mail))
               .doOnError(error -> LOGGER.warn("Error While storing mail. This error will be retried for {} more times.", remainRetries.getAndDecrement(), error));
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org