pub trait Storage: Clone + Send {
    type Error: Error + Send + Sync;

    // Required methods
    fn info<'life0, 'async_trait>(
        &'life0 self,
        job_id: Uuid
    ) -> Pin<Box<dyn Future<Output = Result<Option<JobInfo>, Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn push<'life0, 'async_trait>(
        &'life0 self,
        job: NewJobInfo
    ) -> Pin<Box<dyn Future<Output = Result<Uuid, Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn pop<'life0, 'life1, 'async_trait>(
        &'life0 self,
        queue: &'life1 str,
        runner_id: Uuid
    ) -> Pin<Box<dyn Future<Output = Result<JobInfo, Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn heartbeat<'life0, 'async_trait>(
        &'life0 self,
        job_id: Uuid,
        runner_id: Uuid
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn complete<'life0, 'async_trait>(
        &'life0 self,
        return_job_info: ReturnJobInfo
    ) -> Pin<Box<dyn Future<Output = Result<bool, Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Define a storage backend for jobs

This crate provides a default implementation in the memory_storage module, which is backed by HashMaps and uses counting to assign IDs. If jobs must be persistent across application restarts, look into the sled-backed implementation from the background-jobs-sled-storage crate.

Required Associated Types§

source

type Error: Error + Send + Sync

The error type used by the storage mechansim.

Required Methods§

source

fn info<'life0, 'async_trait>( &'life0 self, job_id: Uuid ) -> Pin<Box<dyn Future<Output = Result<Option<JobInfo>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get the JobInfo for a given job ID

source

fn push<'life0, 'async_trait>( &'life0 self, job: NewJobInfo ) -> Pin<Box<dyn Future<Output = Result<Uuid, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

push a job into the queue

source

fn pop<'life0, 'life1, 'async_trait>( &'life0 self, queue: &'life1 str, runner_id: Uuid ) -> Pin<Box<dyn Future<Output = Result<JobInfo, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

pop a job from the provided queue

source

fn heartbeat<'life0, 'async_trait>( &'life0 self, job_id: Uuid, runner_id: Uuid ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

mark a job as being actively worked on

source

fn complete<'life0, 'async_trait>( &'life0 self, return_job_info: ReturnJobInfo ) -> Pin<Box<dyn Future<Output = Result<bool, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

“Return” a job to the database, marking it for retry if needed

returns true if the job has not been requeued

Object Safety§

This trait is not object safe.

Implementors§