1use std::time::{Duration, SystemTime};
6
7#[derive(Debug, Clone, PartialEq, Eq, Hash)]
9pub struct JobId(pub String);
10
11impl JobId {
12 pub fn generate() -> Self {
13 Self(uuid::Uuid::new_v4().to_string())
14 }
15}
16
17impl std::fmt::Display for JobId {
18 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
19 write!(f, "{}", self.0)
20 }
21}
22
23#[derive(Debug, Clone)]
25pub struct Job {
26 pub id: JobId,
28 pub topic: String,
30 pub payload: Vec<u8>,
32 pub attempt: u32,
34 pub enqueued_at: SystemTime,
36 pub delivered_at: Option<SystemTime>,
38 pub visibility_timeout: Option<Duration>,
40}
41
42impl Job {
43 pub fn new(id: JobId, topic: &str, payload: Vec<u8>) -> Self {
44 Self {
45 id,
46 topic: topic.to_string(),
47 payload,
48 attempt: 0,
49 enqueued_at: SystemTime::now(),
50 delivered_at: Some(SystemTime::now()),
51 visibility_timeout: None,
52 }
53 }
54}