-
Notifications
You must be signed in to change notification settings - Fork 59
Add workflow spec-level retry policies #279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import { computeBackoffDelayMs } from "./backoff.js"; | ||
| import { describe, expect, test } from "vitest"; | ||
|
|
||
| describe("computeBackoffDelayMs", () => { | ||
| test("treats attempt 0 like attempt 1", () => { | ||
| const delayMs = computeBackoffDelayMs( | ||
| { | ||
| initialInterval: "1s", | ||
| backoffCoefficient: 2, | ||
| maximumInterval: "10s", | ||
| }, | ||
| 0, | ||
| ); | ||
|
|
||
| expect(delayMs).toBe(1000); | ||
| }); | ||
|
|
||
| test("uses initial interval on attempt 1", () => { | ||
| const delayMs = computeBackoffDelayMs( | ||
| { | ||
| initialInterval: "250ms", | ||
| backoffCoefficient: 3, | ||
| maximumInterval: "10s", | ||
| }, | ||
| 1, | ||
| ); | ||
|
|
||
| expect(delayMs).toBe(250); | ||
| }); | ||
|
|
||
| test("stays constant when coefficient is 1", () => { | ||
| const delayMs = computeBackoffDelayMs( | ||
| { | ||
| initialInterval: "750ms", | ||
| backoffCoefficient: 1, | ||
| maximumInterval: "10s", | ||
| }, | ||
| 9, | ||
| ); | ||
|
|
||
| expect(delayMs).toBe(750); | ||
| }); | ||
|
|
||
| test("caps delay at maximum interval", () => { | ||
| const delayMs = computeBackoffDelayMs( | ||
| { | ||
| initialInterval: "1s", | ||
| backoffCoefficient: 3, | ||
| maximumInterval: "5s", | ||
| }, | ||
| 4, | ||
| ); | ||
|
|
||
| expect(delayMs).toBe(5000); | ||
| }); | ||
|
|
||
| test("returns finite capped values for very large attempts", () => { | ||
| const delayMs = computeBackoffDelayMs( | ||
| { | ||
| initialInterval: "100ms", | ||
| backoffCoefficient: 2, | ||
| maximumInterval: "60s", | ||
| }, | ||
| 10_000, | ||
| ); | ||
|
|
||
| expect(Number.isFinite(delayMs)).toBe(true); | ||
| expect(delayMs).toBe(60_000); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,42 @@ | ||||||||||||||
| import type { DurationString } from "./duration.js"; | ||||||||||||||
| import { parseDuration } from "./duration.js"; | ||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
| * Shared exponential backoff configuration. | ||||||||||||||
| */ | ||||||||||||||
| export interface BackoffPolicy { | ||||||||||||||
| readonly initialInterval: DurationString; | ||||||||||||||
| readonly backoffCoefficient: number; | ||||||||||||||
| readonly maximumInterval: DurationString; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
| * Compute capped exponential backoff for a 1-based attempt number. | ||||||||||||||
| * @param policy - Backoff policy | ||||||||||||||
| * @param attempt - Attempt number (attempt 1 uses initial interval) | ||||||||||||||
|
Comment on lines
+14
to
+16
|
||||||||||||||
| * Compute capped exponential backoff for a 1-based attempt number. | |
| * @param policy - Backoff policy | |
| * @param attempt - Attempt number (attempt 1 uses initial interval) | |
| * Compute capped exponential backoff for an attempt number (1-based; attempt 0 is treated as 1). | |
| * @param policy - Backoff policy | |
| * @param attempt - Attempt number (attempt >= 0; attempt 0 and 1 use the initial interval) |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding
retryPolicyas a required field onFailWorkflowRunParamsis a breaking change for third-party Backend implementations (the Backend interface is part of the public surface viaOpenWorkflowOptions). If backward compatibility is desired, consider makingretryPolicyoptional and defaulting it internally (or bumping the package version/changelog accordingly).