Skip to main content

Job

Trait Job 

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

    // Required method
    fn handle(&self) -> impl Future<Output = Result<(), AppError>> + Send;
}
Expand description

A unit of deferred work. Implemented once per job type, the same “app implements this once per thing” shape as Policy<U>/Mailable.

Required Associated Constants§

Source

const JOB_TYPE: &'static str

A stable, explicit, app-chosen tag - deliberately not std::any::type_name::<Self>(). That string isn’t stable across a rename/refactor, and a row already sitting in the jobs table under the old name would silently stop matching any handler.

Required Methods§

Source

fn handle(&self) -> impl Future<Output = Result<(), AppError>> + Send

-> impl Future<...> + Send rather than a plain async fn - the exact spelling larust_auth::Authenticatable::find_for_auth already established (see docs/GOTCHAS.md) to avoid the async-fn-in-traits Send-propagation pitfall. Unlike Mailable’s methods, a job’s handle() is inherently real async I/O (sending mail, calling an API, writing to the DB), so - unlike Mailable - there’s no sidestepping this by staying synchronous.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§

Source§

impl Job for MailJob

Source§

const JOB_TYPE: &'static str = "__larust_queued_mail"