use crate::job::{JobEntry, JobStatus};
use async_trait::async_trait;
use uuid::Uuid;
#[derive(Debug, thiserror::Error)]
pub enum QueueError {
#[error("Backend error: {0}")]
Backend(String),
#[error("Job not found")]
NotFound,
#[error("Serialization error: {0}")]
Serialization(#[from] serde_json::Error),
}
#[async_trait]
pub trait QueueBackend: Send + Sync {
async fn enqueue(
&self,
tenant_id: &str,
job_type: &str,
payload: serde_json::Value,
delay_secs: Option<u64>,
) -> Result<Uuid, QueueError>;
async fn dequeue(&self) -> Result<Option<JobEntry>, QueueError>;
async fn update_status(
&self,
id: Uuid,
status: JobStatus,
error: Option<String>,
delay_secs: Option<u64>,
) -> Result<(), QueueError>;
async fn get_status(&self, tenant_id: &str, id: Uuid) -> Result<JobStatus, QueueError>;
async fn get_job(&self, tenant_id: &str, id: Uuid) -> Result<JobEntry, QueueError>;
async fn set_result(&self, id: Uuid, result: serde_json::Value) -> Result<(), QueueError>;
}