1use crate::job::{JobEntry, JobStatus};
4use async_trait::async_trait;
5use uuid::Uuid;
6
7#[derive(Debug, thiserror::Error)]
8pub enum QueueError {
9 #[error("Backend error: {0}")]
10 Backend(String),
11 #[error("Job not found")]
12 NotFound,
13 #[error("Serialization error: {0}")]
14 Serialization(#[from] serde_json::Error),
15}
16
17#[async_trait]
18pub trait QueueBackend: Send + Sync {
19 async fn enqueue(
21 &self,
22 job_type: &str,
23 payload: serde_json::Value,
24 delay_secs: Option<u64>,
25 ) -> Result<Uuid, QueueError>;
26
27 async fn dequeue(&self) -> Result<Option<JobEntry>, QueueError>;
29
30 async fn update_status(
33 &self,
34 id: Uuid,
35 status: JobStatus,
36 error: Option<String>,
37 delay_secs: Option<u64>,
38 ) -> Result<(), QueueError>;
39
40 async fn get_status(&self, id: Uuid) -> Result<JobStatus, QueueError>;
42}