Skip to content

Custom error policy indefinite support#1675

Merged
jeremydmiller merged 3 commits intoJasperFx:mainfrom
punxrok:custom-error-policy-indefinite-support
Sep 5, 2025
Merged

Custom error policy indefinite support#1675
jeremydmiller merged 3 commits intoJasperFx:mainfrom
punxrok:custom-error-policy-indefinite-support

Conversation

@punxrok
Copy link
Copy Markdown
Contributor

@punxrok punxrok commented Sep 4, 2025

When using custom error policies with CustomAction, the action would only execute for the first attempt. On subsequent attempts (attempt 2+), messages would automatically move to the error queue instead of continuing to execute the custom logic. This prevented users from implementing their own retry logic with custom termination conditions.

I added a new CustomActionIndefinitely method that sets the InfiniteSource to allow custom actions to run indefinitely until the user's logic decides to stop.

New Method CustomActionIndefinitely

opts.Policies.OnException<SpecialException>()
    .CustomActionIndefinitely(async (runtime, lifecycle, ex) =>
    {
        if (lifecycle.Envelope.Attempts > 10)
        {
            runtime.MessageTracking.DiscardedEnvelope(lifecycle.Envelope);
            await lifecycle.CompleteAsync();
            return;
        }

        await lifecycle.ReScheduleAsync(DateTimeOffset.Now.AddSeconds(15));
    }, "Handle SpecialException with conditional discard/requeue");

@jeremydmiller
Copy link
Copy Markdown
Member

Can you add some text to the documentation and rebase this one first?

…rce to allow custom actions to run indefinitely until the user's logic decides to stop.

Added a new CustomActionIndefinitely method that sets the InfiniteSource to allow custom actions to run indefinitely until the user's logic decides to stop.
+ added tests
@punxrok punxrok force-pushed the custom-error-policy-indefinite-support branch from d52695c to cb54828 Compare September 5, 2025 11:32
@punxrok
Copy link
Copy Markdown
Contributor Author

punxrok commented Sep 5, 2025

Hey, @jeremydmiller. Done.

…schedule the current in-flight message with a single call.
@jeremydmiller jeremydmiller merged commit dc9e9c9 into JasperFx:main Sep 5, 2025
1 check passed
jeremydmiller pushed a commit that referenced this pull request Sep 5, 2025
… the current in-flight message with a single call.
punxrok pushed a commit to punxrok/wolverine that referenced this pull request Jan 27, 2026
punxrok pushed a commit to punxrok/wolverine that referenced this pull request Jan 27, 2026
…schedule the current in-flight message with a single call.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants