Skip to main content

Job

Trait Job 

Source
pub trait Job:
    Send
    + Sync
    + 'static {
    // Required methods
    fn name(&self) -> &str;
    fn execute(
        &self,
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + '_>>;

    // Provided methods
    fn max_retries(&self) -> u32 { ... }
    fn retry_delay(&self) -> Duration { ... }
}
Expand description

Trait for background jobs.

struct SendEmailJob { pub to: String, pub subject: String }

impl Job for SendEmailJob {
    fn name(&self) -> &str { "send_email" }

    fn execute(&self) -> Pin<Box<dyn Future<Output = Result<(), anyhow::Error>> + Send + '_>> {
        Box::pin(async {
            // send email logic
            Ok(())
        })
    }
}

Required Methods§

Source

fn name(&self) -> &str

Source

fn execute( &self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + '_>>

Provided Methods§

Source

fn max_retries(&self) -> u32

Number of retries on failure (default: 0)

Source

fn retry_delay(&self) -> Duration

Delay between retries (default: 5s)

Implementors§