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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#[derive(Debug)]
pub struct Message<T, R> {
    inner: T,
    result_tx: Option<tokio::sync::oneshot::Sender<R>>,
}

impl<T, R> Message<T, R>
where
    T: Sized + Send + Clone,
    R: Sized + Send,
{
    pub fn new(inner: T, result_tx: Option<tokio::sync::oneshot::Sender<R>>) -> Self {
        Self { inner, result_tx }
    }

    pub fn inner(&self) -> T {
        self.inner.clone()
    }

    pub fn result_tx(self) -> Option<tokio::sync::oneshot::Sender<R>> {
        self.result_tx
    }
}

pub struct JobSpec {
    max_iter: Option<usize>,
    interval: Option<std::time::Duration>,
    start_at: std::time::SystemTime,
}

impl JobSpec {
    pub fn new(
        max_iter: Option<usize>,
        interval: Option<std::time::Duration>,
        start_at: std::time::SystemTime,
    ) -> Self {
        if let None = interval {
            Self {
                max_iter: Some(1),
                interval,
                start_at,
            }
        } else {
            Self {
                max_iter,
                interval,
                start_at,
            }
        }
    }

    pub fn max_iter(&self) -> Option<usize> {
        self.max_iter
    }

    pub fn start_at(&self) -> std::time::SystemTime {
        self.start_at
    }

    pub fn interval(&self) -> Option<std::time::Duration> {
        self.interval
    }
}

impl Default for JobSpec {
    fn default() -> Self {
        Self {
            max_iter: Some(1),
            interval: None,
            start_at: std::time::SystemTime::now(),
        }
    }
}