vex_queue/
backend.rs

1//! Queue Backend Trait
2
3use 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    /// Enqueue a job payload for a specific tenant
20    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    /// Pull next available job
29    async fn dequeue(&self) -> Result<Option<JobEntry>, QueueError>;
30
31    /// Update job status (ack/nack)
32    /// `delay_secs` is used for retries - how long to wait before the job is available again
33    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    /// Get job status
42    async fn get_status(&self, id: Uuid) -> Result<JobStatus, QueueError>;
43}