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
20    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    /// Pull next available job
28    async fn dequeue(&self) -> Result<Option<JobEntry>, QueueError>;
29
30    /// Update job status (ack/nack)
31    /// `delay_secs` is used for retries - how long to wait before the job is available again
32    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    /// Get job status
41    async fn get_status(&self, id: Uuid) -> Result<JobStatus, QueueError>;
42}