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 tenant_id: &str,
23 job_type: &str,
24 payload: serde_json::Value,
25 delay_secs: Option<u64>,
26 ) -> Result<Uuid, QueueError>;
27
28 async fn dequeue(&self) -> Result<Option<JobEntry>, QueueError>;
30
31 async fn update_status(
34 &self,
35 id: Uuid,
36 status: JobStatus,
37 error: Option<String>,
38 delay_secs: Option<u64>,
39 ) -> Result<(), QueueError>;
40
41 async fn get_status(&self, id: Uuid) -> Result<JobStatus, QueueError>;
43}