Skip to main content

Job

Trait Job 

Source
pub trait Job:
    Serialize
    + DeserializeOwned
    + Send
    + Sync
    + 'static {
    const NAME: &'static str;

    // Required method
    fn run<'life0, 'life1, 'async_trait>(
        &'life0 self,
        cx: &'life1 JobCx,
    ) -> Pin<Box<dyn Future<Output = Result<(), JobError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided methods
    fn queue(&self) -> String { ... }
    fn tries(&self) -> u32 { ... }
    fn backoff(&self, attempt: u32) -> Duration { ... }
    fn timeout(&self) -> Option<Duration> { ... }
    fn retry_until(&self) -> Option<DateTime<Utc>> { ... }
    fn unique_key(&self) -> Option<String> { ... }
}
Expand description

Work to run later. The struct is the payload: whatever it carries is stored as JSON and read back by the worker.

Required Associated Constants§

Source

const NAME: &'static str

The job’s name, unique across the application: acme.blog::send_digest.

Required Methods§

Source

fn run<'life0, 'life1, 'async_trait>( &'life0 self, cx: &'life1 JobCx, ) -> Pin<Box<dyn Future<Output = Result<(), JobError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Provided Methods§

Source

fn queue(&self) -> String

The queue the job lands on. DEFAULT_QUEUE unless overridden.

Source

fn tries(&self) -> u32

How many attempts before the job fails; 0 means as many as the retry window allows. Three unless overridden.

Source

fn backoff(&self, attempt: u32) -> Duration

How long to wait before attempt attempt + 1, after attempt attempt failed. Ten seconds, doubling each time, unless overridden.

Source

fn timeout(&self) -> Option<Duration>

How long one attempt may run. A minute unless overridden; None means no limit.

Source

fn retry_until(&self) -> Option<DateTime<Utc>>

Keep retrying until this moment, whatever tries says. None unless overridden.

Source

fn unique_key(&self) -> Option<String>

A key no two pending jobs may share: a push while one with the same key waits is dropped. None unless overridden.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§