Skip to main content

RETRY

Constant RETRY 

Source
pub const RETRY: &str = "machine Retry<T> {\r\n    state Ready(max_attempts: i64, base_delay_ms: i64, max_delay_ms: i64, jitter_pct: i64)\r\n    state Attempting(attempt: i64, max_attempts: i64, base_delay_ms: i64, max_delay_ms: i64, jitter_pct: i64)\r\n    state Waiting(attempt: i64, delay_ms: i64, max_attempts: i64, base_delay_ms: i64, max_delay_ms: i64, jitter_pct: i64)\r\n    state Succeeded(value: T, attempts: i64)\r\n    state Failed(error: String, attempts: i64)\r\n\r\n    transition begin: Ready -> Attempting\r\n    transition run: Attempting -> Waiting | Succeeded | Failed\r\n    transition wait_complete: Waiting -> Attempting\r\n\r\n    async effect execute_operation() -> Result<T, String>\r\n    async effect sleep_ms(duration_ms: i64) -> i64\r\n    effect compute_backoff(base_delay_ms: i64, attempt: i64, max_delay_ms: i64, jitter_pct: i64) -> i64\r\n\r\n    on begin() {\r\n        goto Attempting(1, max_attempts, base_delay_ms, max_delay_ms, jitter_pct);\r\n    }\r\n\r\n    async on run() {\r\n        let result = perform execute_operation();\r\n        match result {\r\n            Ok(value) => {\r\n                goto Succeeded(value, attempt);\r\n            }\r\n            Err(err) => {\r\n                if attempt >= max_attempts {\r\n                    goto Failed(err, attempt);\r\n                } else {\r\n                    let delay = perform compute_backoff(base_delay_ms, attempt, max_delay_ms, jitter_pct);\r\n                    goto Waiting(attempt, delay, max_attempts, base_delay_ms, max_delay_ms, jitter_pct);\r\n                }\r\n            }\r\n        }\r\n    }\r\n\r\n    async on wait_complete() {\r\n        let _slept = perform sleep_ms(delay_ms);\r\n        goto Attempting(attempt + 1, max_attempts, base_delay_ms, max_delay_ms, jitter_pct);\r\n    }\r\n}\r\n";
Expand description

The Gust source for the Retry machine.

Provides configurable retry logic with exponential backoff and jitter. States include Ready, Attempting, Waiting, Succeeded, and Failed. Tracks attempt count, base and max delay, and jitter percentage.

Generic over T for the value type returned on success.