use std::time::{Duration, SystemTime};
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct JobId(pub String);
impl JobId {
pub fn generate() -> Self {
Self(uuid::Uuid::new_v4().to_string())
}
}
impl std::fmt::Display for JobId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
#[derive(Debug, Clone)]
pub struct Job {
pub id: JobId,
pub topic: String,
pub payload: Vec<u8>,
pub attempt: u32,
pub enqueued_at: SystemTime,
pub delivered_at: Option<SystemTime>,
pub visibility_timeout: Option<Duration>,
}
impl Job {
pub fn new(id: JobId, topic: &str, payload: Vec<u8>) -> Self {
let now = SystemTime::now();
Self {
id,
topic: topic.to_string(),
payload,
attempt: 0,
enqueued_at: now,
delivered_at: Some(now),
visibility_timeout: None,
}
}
}