replicate_rust/retry.rs
1//! Helper struct for the prediction struct. Used to retry pooling the api for latest prediction status until it is completed.
2
3/// Strategy to use for retrying. Currently only fixed delay is supported.
4pub enum RetryStrategy {
5 // Retry with a fixed delay.
6 FixedDelay(u64),
7 // Retry with an exponential backoff.
8 // ExponentialBackoff(u32),
9}
10
11/// TODO : Unimplemented
12pub struct RetryPolicy {
13 pub max_retries: u32,
14 pub strategy: RetryStrategy,
15 // step: u32,
16}
17
18impl RetryPolicy {
19 pub fn new(max_retries: u32, strategy: RetryStrategy) -> Self {
20 Self {
21 max_retries,
22 strategy,
23 // step: 0,
24 }
25 }
26
27 pub fn step(&self) {
28 match self.strategy {
29 RetryStrategy::FixedDelay(delay) => {
30 std::thread::sleep(std::time::Duration::from_millis(delay))
31 } // RetryStrategy::ExponentialBackoff(delay) => delay * attempt,
32 }
33 }
34}