pub trait Job:
Serialize
+ DeserializeOwned
+ Send
+ Sync
+ 'static {
const NAME: &'static str;
const QUEUE: &'static str = "default";
const MAX_ATTEMPTS: u32 = 3;
const TIMEOUT: Duration = _;
const ENCRYPTED: bool = false;
const UNIQUE_FOR: Option<Duration> = None;
// Required method
fn handle(self, ctx: JobContext) -> impl Future<Output = Result> + Send;
// Provided methods
fn backoff(attempt: u32) -> Duration { ... }
fn unique_id(&self) -> String { ... }
fn middleware(&self) -> Vec<Middleware> { ... }
fn failed(
self,
ctx: JobContext,
error: String,
) -> impl Future<Output = ()> + Send { ... }
}Expand description
A unit of background work. It is stored as JSON, so keep it to ids and small values rather than whole models.
Required Associated Constants§
Provided Associated Constants§
Sourceconst QUEUE: &'static str = "default"
const QUEUE: &'static str = "default"
Its queue; queue:work --queue high,default drains queues in order.
Sourceconst MAX_ATTEMPTS: u32 = 3
const MAX_ATTEMPTS: u32 = 3
Runs before the job is moved to failed_jobs.
Sourceconst ENCRYPTED: bool = false
const ENCRYPTED: bool = false
Store the payload encrypted with APP_KEY (it holds personal data or
secrets). The worker decrypts it; failed_jobs keeps it encrypted.
Sourceconst UNIQUE_FOR: Option<Duration> = None
const UNIQUE_FOR: Option<Duration> = None
While a job with the same Job::unique_id is queued or running,
dispatching another returns the queued one’s id instead, for up to
this long (the claim is dropped when the job finishes).
Required Methods§
Provided Methods§
Sourcefn backoff(attempt: u32) -> Duration
fn backoff(attempt: u32) -> Duration
Wait before retrying after the given failed attempt (1-based).
Sourcefn unique_id(&self) -> String
fn unique_id(&self) -> String
What makes two jobs “the same” for Job::UNIQUE_FOR, e.g. the
order id. Empty (the default) makes every job of the type the same.
Sourcefn middleware(&self) -> Vec<Middleware>
fn middleware(&self) -> Vec<Middleware>
Conditions checked before each attempt; a job that can’t run yet is put back without using up an attempt.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".