Skip to main content

capmonstercloud_client/
timeouts.rs

1//! Polling schedule of `getTaskResult` for one task type.
2
3use std::time::Duration;
4
5/// How long to wait before the first poll, how often to poll, and when to give up.
6#[derive(Debug, Clone, Copy, PartialEq)]
7pub struct GetResultTimeouts {
8    /// Pause between `createTask` and the first `getTaskResult`.
9    pub first_request_delay: Duration,
10    /// Same as above for the "no cache" mode. Kept for parity with the other SDKs; currently unused.
11    pub first_request_no_cache_delay: Duration,
12    /// Pause between two consecutive `getTaskResult` calls.
13    pub requests_interval: Duration,
14    /// Total time after which `Error::Timeout` is returned.
15    pub timeout: Duration,
16}
17
18impl GetResultTimeouts {
19    pub fn new(
20        first_request_delay: Duration,
21        first_request_no_cache_delay: Duration,
22        requests_interval: Duration,
23        timeout: Duration,
24    ) -> Self {
25        Self {
26            first_request_delay,
27            first_request_no_cache_delay,
28            requests_interval,
29            timeout,
30        }
31    }
32
33    /// Same as [`Self::new`] with the values given in seconds. Only used for the built-in
34    /// per-type constants, which are always finite and non-negative.
35    pub(crate) fn secs(
36        first_delay: f64,
37        first_no_cache_delay: f64,
38        interval: f64,
39        timeout: f64,
40    ) -> Self {
41        Self::new(
42            Duration::from_secs_f64(first_delay),
43            Duration::from_secs_f64(first_no_cache_delay),
44            Duration::from_secs_f64(interval),
45            Duration::from_secs_f64(timeout),
46        )
47    }
48}