1use crate::error::Result;
2use async_trait::async_trait;
3use chrono::{DateTime, Utc};
4use std::collections::HashMap;
5
6pub struct EnqueueRequest {
7 pub job_type: String,
8 pub queue: String,
9 pub payload: Vec<u8>,
10 pub max_retries: u32,
11 pub priority: i32,
12 pub scheduled_at: DateTime<Utc>,
13}
14
15pub use crate::job::{JobId, RawJob};
16
17#[async_trait]
18pub trait Queue: Send + Sync + 'static {
19 async fn push(&self, req: EnqueueRequest) -> Result<JobId>;
20
21 async fn pop(&self, queues: &[&str]) -> Result<Option<RawJob>>;
22
23 async fn ack(&self, id: JobId) -> Result<()>;
24
25 async fn fail(&self, id: JobId, err: &str) -> Result<()>;
26
27 async fn retry(&self, id: JobId, retry_at: DateTime<Utc>) -> Result<()>;
28
29 async fn get(&self, id: JobId) -> Result<Option<RawJob>>;
30
31 async fn list(
32 &self,
33 queue: &str,
34 status: Option<&str>,
35 limit: usize,
36 offset: usize,
37 ) -> Result<Vec<RawJob>>;
38
39 async fn queue_depths(&self) -> Result<HashMap<String, u64>>;
40}