1#[derive(Debug)]
2pub struct Message {
8 inner: Vec<u8>,
9 result_tx: Option<tokio::sync::oneshot::Sender<Vec<u8>>>,
10}
11impl Clone for Message {
12 fn clone(&self) -> Self {
13 Self {
14 inner: self.inner.clone(),
15 result_tx: None,
16 }
17 }
18}
19
20impl Message {
21 pub fn new(inner: Vec<u8>, result_tx: Option<tokio::sync::oneshot::Sender<Vec<u8>>>) -> Self {
22 Self { inner, result_tx }
23 }
24
25 pub fn inner(&self) -> &Vec<u8> {
26 &self.inner
27 }
28
29 pub fn result_tx(&mut self) -> Option<tokio::sync::oneshot::Sender<Vec<u8>>> {
30 let tx = self.result_tx.take();
31 self.result_tx = None;
32 tx
33 }
34}
35
36#[derive(Debug, Clone)]
37pub struct JobSpec {
45 max_iter: Option<usize>,
46 interval: Option<std::time::Duration>,
47 start_at: std::time::SystemTime,
48}
49
50impl JobSpec {
51 pub fn new(
52 max_iter: Option<usize>,
53 interval: Option<std::time::Duration>,
54 start_at: std::time::SystemTime,
55 ) -> Self {
56 if let None = interval {
57 Self {
58 max_iter: Some(1),
59 interval,
60 start_at,
61 }
62 } else {
63 Self {
64 max_iter,
65 interval,
66 start_at,
67 }
68 }
69 }
70
71 pub fn max_iter(&self) -> Option<usize> {
72 self.max_iter
73 }
74
75 pub fn start_at(&self) -> std::time::SystemTime {
76 self.start_at
77 }
78
79 pub fn interval(&self) -> Option<std::time::Duration> {
80 self.interval
81 }
82}
83
84impl Default for JobSpec {
85 fn default() -> Self {
86 Self {
87 max_iter: Some(1),
88 interval: None,
89 start_at: std::time::SystemTime::now(),
90 }
91 }
92}