1use crate::error::Result;
2use async_trait::async_trait;
3use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5
6pub mod memory;
7
8#[cfg(feature = "redis")]
9pub mod redis;
10
11#[cfg(feature = "postgres")]
12pub mod postgres;
13
14#[derive(Debug, Clone, Serialize, Deserialize)]
16pub struct JobRequest {
17 pub id: String,
18 pub name: String,
19 pub payload: serde_json::Value,
20 pub created_at: DateTime<Utc>,
21 pub attempts: u32,
22 pub max_attempts: u32,
23 pub last_error: Option<String>,
24 pub run_at: Option<DateTime<Utc>>,
25}
26
27#[async_trait]
29pub trait JobBackend: Send + Sync {
30 async fn push(&self, job: JobRequest) -> Result<()>;
32
33 async fn pop(&self) -> Result<Option<JobRequest>>;
36
37 async fn complete(&self, job_id: &str) -> Result<()>;
39
40 async fn fail(&self, job_id: &str, error: &str) -> Result<()>;
43}