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