use anyhow::Error; use background_jobs_core::{JobInfo, NewJobInfo, ReturnJobInfo, Storage}; use uuid::Uuid; #[async_trait::async_trait] pub(crate) trait ActixStorage { async fn push(&self, job: NewJobInfo) -> Result; async fn pop(&self, queue: &str, runner_id: Uuid) -> Result; async fn heartbeat(&self, job_id: Uuid, runner_id: Uuid) -> Result<(), Error>; async fn complete(&self, ret: ReturnJobInfo) -> Result<(), Error>; } pub(crate) struct StorageWrapper(pub(crate) S) where S: Storage + Send + Sync, S::Error: Send + Sync + 'static; #[async_trait::async_trait] impl ActixStorage for StorageWrapper where S: Storage + Send + Sync, S::Error: Send + Sync + 'static, { async fn push(&self, job: NewJobInfo) -> Result { Ok(self.0.push(job).await?) } async fn pop(&self, queue: &str, runner_id: Uuid) -> Result { Ok(self.0.pop(queue, runner_id).await?) } async fn heartbeat(&self, job_id: Uuid, runner_id: Uuid) -> Result<(), Error> { Ok(self.0.heartbeat(job_id, runner_id).await?) } async fn complete(&self, ret: ReturnJobInfo) -> Result<(), Error> { self.0.complete(ret).await?; Ok(()) } }