1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//! Helper struct for the prediction struct. Used to retry pooling the api for latest prediction status until it is completed.

/// Strategy to use for retrying. Currently only fixed delay is supported.
pub enum RetryStrategy {
    // Retry with a fixed delay.
    FixedDelay(u64),
    // Retry with an exponential backoff.
    // ExponentialBackoff(u32),
}

/// TODO : Unimplemented
pub struct RetryPolicy {
    pub max_retries: u32,
    pub strategy: RetryStrategy,
    // step: u32,
}

impl RetryPolicy {
    pub fn new(max_retries: u32, strategy: RetryStrategy) -> Self {
        Self {
            max_retries,
            strategy,
            // step: 0,
        }
    }

    pub fn step(&self) {
        match self.strategy {
            RetryStrategy::FixedDelay(delay) => {
                std::thread::sleep(std::time::Duration::from_millis(delay))
            } // RetryStrategy::ExponentialBackoff(delay) => delay * attempt,
        }
    }
}