spring-projects / spring-projects/spring-modulith

Introduce FailedAttemptInfo for better retries

Open
#1,458 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

in: event publication registry type: enhancement
Dominant language
Java
Stars
1.2k
Forks
222
PR merge metrics
No merged PRs in 30d

Description

Hello.

When an event publication is failing it would be useful to know which was the cause - exception, when it happened and how many failed attempts were when retrying.

Introducing an extra parameter to EventPublicationRegistry.markFailed(Object event, PublicationTargetIdentifier targetIdentifier, Throwable exception) will help to store the exception.

The EventPublication interface would also provide List<FailedAttemptInfo> getFailedAttempts();


public interface FailedAttemptInfo {
    /**
     * Returns the time the event is published at.
     *
     * @return will never be {@literal null}.
     */
    Instant getPublicationDate();

    /**
     * Returns the exception causing the publication to fail
     *
     * @return will never be {@literal null}.
     */
    Throwable getFailureReason();
}

When users of the library will call IncompleteEventPublications.resubmitIncompletePublications we can take into account the number of failed attempts, the error and when it happened. Incomplete publications could be retriggered with a predicate like:

incompletePublications.resubmitIncompletePublications(e -> {
				if (e.getFailedAttempts().size() > 10) {
					return false;
				}
				return e.getFailedAttempts().stream()
						.map(FailedAttemptInfo::getFailureReason)
						.anyMatch(reason-> reason instanceof SomeOtherException);
			});

With this approach, the DefaultEventPublication would need to store the list of failed attempts and also for the other events-*** modules, the information needs to be persisted.

Not sure if this approach would fit the current design of the library. I could also help adding this with a PR later.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading EventPublicationRegistry.markFailed, EventPublication, DefaultEventPublication, and IncompleteEventPublications.resubmitIncompletePublications. Trace how failed publications are handled in the other events-* modules before deciding whether the proposed FailedAttemptInfo design fits. Done means failed attempts expose their dates and causes, support the retry predicate, and are persisted where required.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.