Trait background_jobs::ActixJob[][src]

pub trait ActixJob: 'static + Serialize + DeserializeOwned {
    type State: 'static + Clone;
    type Future: Future;

    const NAME: &'static str;
    const QUEUE: &'static str;
    const MAX_RETRIES: MaxRetries;
    const BACKOFF: Backoff;
    const TIMEOUT: i64;

    fn run(self, state: Self::State) -> Self::Future;

    fn queue(&self) -> &str { ... }
fn max_retries(&self) -> MaxRetries { ... }
fn backoff_strategy(&self) -> Backoff { ... }
fn timeout(&self) -> i64 { ... } }
Expand description

The ActixJob trait defines parameters pertaining to an instance of background job

This trait is specific to Actix, and will automatically implement the Job trait with the proper translation from ?Send futures to Send futures

Associated Types

The application state provided to this job at runtime.

The future returned by this job

Importantly, this Future does not require Send

Associated Constants

The name of the job

This name must be unique!!!

The name of the default queue for this job

This can be overridden on an individual-job level, but if a non-existant queue is supplied, the job will never be processed.

Define the default number of retries for this job

Defaults to Count(5) Jobs can override

Define the default backoff strategy for this job

Defaults to Exponential(2) Jobs can override

Define the maximum number of milliseconds a job should be allowed to run before being considered dead.

This is important for allowing the job server to reap processes that were started but never completed.

Defaults to 15 seconds Jobs can override

Required methods

Users of this library must define what it means to run a job.

This should contain all the logic needed to complete a job. If that means queuing more jobs, sending an email, shelling out (don’t shell out), or doing otherwise lengthy processes, that logic should all be called from inside this method.

The state passed into this job is initialized at the start of the application. The state argument could be useful for containing a hook into something like r2d2, or the address of an actor in an actix-based system.

Provided methods

If this job should not use it’s default queue, this can be overridden in user-code.

If this job should not use it’s default maximum retry count, this can be overridden in user-code.

If this job should not use it’s default backoff strategy, this can be overridden in user-code.

Define the maximum number of milliseconds this job should be allowed to run before being considered dead.

This is important for allowing the job server to reap processes that were started but never completed.

Implementors