use std::time::Duration;
use chrono::{DateTime, Utc};
use async_trait::async_trait;
use crate::{
error::Result,
job::{JobId, JobRecord, QueueStats},
};
#[async_trait]
pub trait Backend: Send + Sync + 'static {
async fn enqueue(&self, record: JobRecord) -> Result<JobId>;
async fn claim(
&self,
queues: &[&str],
timeout: Duration,
) -> Result<Option<JobRecord>>;
async fn ack(&self, id: JobId) -> Result<()>;
async fn nack(
&self,
id: JobId,
error: &str,
retry_at: Option<DateTime<Utc>>,
) -> Result<()>;
async fn heartbeat(&self, id: JobId) -> Result<()>;
async fn reap_stuck(&self, older_than: Duration) -> Result<u64>;
async fn stats(&self, queue: &str) -> Result<QueueStats>;
async fn dead_jobs(
&self,
queue: &str,
limit: i64,
offset: i64,
) -> Result<Vec<JobRecord>>;
async fn retry_dead(&self, id: JobId) -> Result<()>;
async fn retry_all_dead(&self, queue: &str) -> Result<u64>;
}