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
use crate::FunctionName;
use crate::ZomeName;
use std::time::Duration;
pub const SCHEDULER_INTERVAL: Duration = Duration::from_millis(100);
pub const PERSISTED_TIMEOUT: Duration = Duration::from_millis(20000);
#[derive(Debug, thiserror::Error)]
pub enum ScheduleError {
#[error("{0}")]
Cron(String),
#[error(transparent)]
Timestamp(crate::timestamp::TimestampError),
}
#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone)]
pub enum Schedule {
Persisted(String),
Ephemeral(Duration),
}
impl From<String> for Schedule {
fn from(cron: String) -> Self {
Self::Persisted(cron)
}
}
impl From<Duration> for Schedule {
fn from(timeout: Duration) -> Self {
Self::Ephemeral(timeout)
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct ScheduledFn(ZomeName, FunctionName);
impl ScheduledFn {
pub fn new(zome_name: ZomeName, fn_name: FunctionName) -> Self {
Self(zome_name, fn_name)
}
pub fn zome_name(&self) -> &ZomeName {
&self.0
}
pub fn fn_name(&self) -> &FunctionName {
&self.1
}
}