Skip to main content

Module job

Module job 

Source
Expand description

What a job is, and how a worker finds one again after it has been stored.

ⓘ
struct SendWelcomeEmail { user_id: i64 }

impl Job for SendWelcomeEmail {
    const NAME: &'static str = "send-welcome-email";

    fn payload(&self) -> Json {
        Json::object([("user_id", Json::from(self.user_id))])
    }

    fn from_payload(payload: &Json) -> Result<Self> {
        Ok(SendWelcomeEmail { user_id: payload.get("user_id").and_then(Json::as_i64).unwrap_or(0) })
    }

    fn handle(&self) -> impl Future<Output = Result<()>> + Send {
        async move { Ok(()) }
    }
}

Structs§

FailedJob
A job that used up every attempt, kept so a human can look at it.
JobRegistry
The map from a stored job name back to code that can run it.
QueuedJob
A job as it is stored: a name, a payload, and the policy for running it.
ReservedJob
A job a worker has taken off the queue and is responsible for.

Constants§

DEFAULT_QUEUE
The queue a job goes on when it does not ask for another.
DEFAULT_RETRY_AFTER
The base delay before a failed job is retried. Doubled on each attempt by the worker’s backoff.
DEFAULT_TRIES
How many times a job is attempted before it is considered dead.

Traits§

Job
A unit of work that can be stored and run later.

Type Aliases§

BoxFuture
A boxed future, the shape everything dyn-compatible in this crate returns.