redup_abstractions/
probe.rs1use std::time::Duration;
4
5use tokio::sync::watch;
6use tokio_util::sync::CancellationToken;
7
8use crate::observation::Observation;
9
10#[derive(Debug, Clone)]
12pub struct Attempt {
13 timeout: Duration,
14 token: CancellationToken,
15}
16
17impl Attempt {
18 pub fn new(timeout: Duration, token: CancellationToken) -> Self {
20 Self { timeout, token }
21 }
22
23 pub fn timeout(&self) -> Duration {
25 self.timeout
26 }
27
28 pub fn token(&self) -> &CancellationToken {
30 &self.token
31 }
32}
33
34#[derive(Debug, Clone, Copy)]
36pub struct ProbeSettings {
37 pull_delay: Duration,
38 timeout: Duration,
39}
40
41impl ProbeSettings {
42 pub fn new(pull_delay: Duration, timeout: Duration) -> Self {
44 Self {
45 pull_delay,
46 timeout,
47 }
48 }
49
50 pub fn pull_delay(&self) -> Duration {
52 self.pull_delay
53 }
54
55 pub fn timeout(&self) -> Duration {
57 self.timeout
58 }
59}
60
61#[async_trait::async_trait]
67pub trait Probe: Send + Sync {
68 async fn run(
70 &self,
71 settings: &ProbeSettings,
72 states: watch::Sender<Observation>,
73 token: CancellationToken,
74 );
75}