pub trait Job:
Send
+ Sync
+ 'static {
type Payload: Serialize + DeserializeOwned + Send + Sync + 'static;
type Output: Serialize + DeserializeOwned + Send + Sync + 'static;
const KIND: &'static str;
// Required method
fn run<'life0, 'async_trait>(
&'life0 self,
ctx: JobContext,
payload: Self::Payload,
) -> Pin<Box<dyn Future<Output = Result<Self::Output, Box<dyn Error + Sync + Send>>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait;
}Expand description
A typed background job.
Implementors declare a serde-serializable Payload, a unique
KIND string used for dispatch, and an async
run method.
Handlers must be idempotent. Delivery is at-least-once: a lease that
expires before the job is resolved makes the job visible again, so a handler
can run more than once for the same job. This happens on a worker crash, but
also when the broker’s wall clock steps forward (e.g. an NTP jump) past a
reserved job’s remaining lease — expiring it while the original handler is
still running. run must therefore tolerate re-execution (e.g. guard side
effects with the JobContext::id or an external dedup key); the broker does
not prevent duplicate execution.
Required Associated Constants§
Required Associated Types§
Required Methods§
Sourcefn run<'life0, 'async_trait>(
&'life0 self,
ctx: JobContext,
payload: Self::Payload,
) -> Pin<Box<dyn Future<Output = Result<Self::Output, Box<dyn Error + Sync + Send>>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn run<'life0, 'async_trait>(
&'life0 self,
ctx: JobContext,
payload: Self::Payload,
) -> Pin<Box<dyn Future<Output = Result<Self::Output, Box<dyn Error + Sync + Send>>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Execute the job. Returning Err causes a retry (until attempts are
exhausted) or dead-lettering.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".