Skip to content

Step Should Retry support#427

Merged
devhawk merged 4 commits into
mainfrom
devhawk/step-should-retry
Jun 10, 2026
Merged

Step Should Retry support#427
devhawk merged 4 commits into
mainfrom
devhawk/step-should-retry

Conversation

@devhawk

@devhawk devhawk commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

Adds a shouldRetry predicate to steps, allowing callers to short-circuit retries on specific exception types rather than always exhausting maxAttempts.

Two ways to specify the predicate:

  • Annotation (@Step): provide a Class<? extends StepShouldRetry> — the class is instantiated via reflection at runtime. StepShouldRetry is a functional interface w/ boolean shouldRetry(Throwable) method.
@Step(maxAttempts = 5, shouldRetry = MyRetryPolicy.class)
public String myStep(String input) { ... }
  • Programmatic (StepOptions): pass a Predicate directly, suitable for inline steps or lambdas.
dbos.runStep(
  () -> { ... },
  new StepOptions("myStep")
    .withMaxAttempts(5)
    .withShouldRetry(e -> !(e instanceof FatalException)));

When shouldRetry returns false, the step aborts immediately and rethrows the original exception. When it returns true (or is not set), normal retry-with-backoff behavior applies.

Implementation notes

  • StepShouldRetry.None is a sentinel inner class used as the annotation default, since Java annotations cannot use null as an element default value.
  • StepShouldRetry implementers must have a public no-arg constructor

fixes #413

@devhawk devhawk requested review from kraftp, maxdml and qianl15 June 9, 2026 23:01
@devhawk devhawk requested a review from kraftp June 9, 2026 23:53
@devhawk devhawk merged commit 253f6cc into main Jun 10, 2026
18 checks passed
@devhawk devhawk deleted the devhawk/step-should-retry branch June 10, 2026 00:26
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.

Configurable Error Retrying For Steps

2 participants