tokio_cron_scheduler/job/
job_data.rs

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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#[derive(Clone, PartialEq, Debug)]
pub struct CronJob {
    pub schedule: String,
}
#[derive(Clone, PartialEq, Debug)]
pub struct NonCronJob {
    pub repeating: bool,
    pub repeated_every: u64,
}
#[derive(Clone, PartialEq, Debug)]
pub struct Uuid {
    pub id1: u64,
    pub id2: u64,
}
#[derive(Clone, PartialEq, Debug)]
pub struct JobStoredData {
    pub id: ::core::option::Option<Uuid>,
    pub last_updated: ::core::option::Option<u64>,
    pub last_tick: ::core::option::Option<u64>,
    pub next_tick: u64,
    pub job_type: i32,
    pub count: u32,
    pub extra: Vec<u8>,
    pub ran: bool,
    pub stopped: bool,
    pub job: ::core::option::Option<job_stored_data::Job>,
}

/// Nested message and enum types in `JobStoredData`.
pub mod job_stored_data {
    #[derive(Clone, PartialEq, Debug)]
    #[repr(i32)]
    pub enum Job {
        CronJob(super::CronJob),
        NonCronJob(super::NonCronJob),
    }
}
#[derive(Clone, PartialEq, Debug)]
pub struct JobIdAndNotification {
    pub job_id: ::core::option::Option<Uuid>,
    pub notification_id: ::core::option::Option<Uuid>,
}
#[derive(Clone, PartialEq, Debug)]
pub struct NotificationData {
    pub job_id: ::core::option::Option<JobIdAndNotification>,
    pub job_states: Vec<i32>,
    pub extra: Vec<u8>,
}
#[derive(Clone, PartialEq, Debug)]
pub struct NotificationIdAndState {
    pub notification_id: ::core::option::Option<Uuid>,
    pub job_state: i32,
}
#[derive(Clone, PartialEq, Debug)]
pub struct JobAndNextTick {
    pub id: ::core::option::Option<Uuid>,
    pub job_type: i32,
    pub next_tick: u64,
    pub last_tick: ::core::option::Option<u64>,
}
#[derive(Clone, PartialEq, Debug)]
pub struct ListOfUuids {
    pub uuids: Vec<Uuid>,
}
#[derive(Clone, PartialEq, Debug)]
pub struct JobAndNotifications {
    pub job_id: ::core::option::Option<Uuid>,
    pub notification_ids: Vec<Uuid>,
}
#[derive(Clone, PartialEq, Debug)]
pub struct ListOfJobsAndNotifications {
    pub job_and_notifications: Vec<JobAndNotifications>,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, FromPrimitive, ToPrimitive)]
#[repr(i32)]
pub enum JobState {
    Stop = 0,
    Scheduled = 1,
    Started = 2,
    Done = 3,
    Removed = 4,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, FromPrimitive, ToPrimitive)]
#[repr(i32)]
pub enum JobType {
    Cron = 0,
    Repeated = 1,
    OneShot = 2,
}

impl JobState {
    pub fn from_i32(x: i32) -> Option<Self> {
        match x {
            0 => Some(Self::Stop),
            1 => Some(Self::Scheduled),
            2 => Some(Self::Started),
            3 => Some(Self::Done),
            4 => Some(Self::Removed),
            _ => None,
        }
    }
}

impl JobType {
    pub fn from_i32(x: i32) -> Option<Self> {
        match x {
            0 => Some(Self::Cron),
            1 => Some(Self::Repeated),
            2 => Some(Self::OneShot),
            _ => None,
        }
    }
}

impl From<JobState> for i32 {
    fn from(val: JobState) -> Self {
        val as i32
    }
}

impl From<JobType> for i32 {
    fn from(val: JobType) -> Self {
        val as i32
    }
}

impl JobStoredData {
    pub fn job_type(&self) -> JobType {
        JobType::from_i32(self.job_type).unwrap()
    }
}