1use std::{sync::Arc, time::Duration};
2
3use chrono::{DateTime, Utc};
4
5#[derive(Clone, Copy, Debug, serde::Deserialize, serde::Serialize)]
6pub struct ScheduleInfo {
7 pub at: DateTime<Utc>,
8 pub last_attempt: Option<DateTime<Utc>>,
9}
10
11impl ScheduleInfo {
12 pub fn last_interval(&self) -> Result<Option<Duration>, time::OutOfRangeError> {
13 self.last_attempt
14 .map(|last| (last - self.at).to_std())
15 .transpose()
16 }
17}
18
19#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
20pub struct QueueId(pub Arc<String>);
21
22impl QueueId {
23 pub fn new<S: ToString>(s: S) -> QueueId {
24 QueueId(Arc::new(s.to_string()))
25 }
26}