Expand description
The queue: work pushed now and run by a worker, with retries, a failed list and a lifetime per job.
A job is a serde struct that implements Job; a module registers it
by type, and a payload names it. Pushing records the job; a worker claims
it, runs it under its timeout, deletes it on success, releases it with
its backoff on failure, and moves it to the failed list once its tries or
its retry window are spent.
ⓘ
use laterite_core::queue::{Job, JobCx, JobError, QueueRegistry};
#[derive(Serialize, Deserialize)]
struct SendDigest { user_id: i64 }
#[async_trait]
impl Job for SendDigest {
const NAME: &'static str = "acme.blog::send_digest";
async fn run(&self, cx: &JobCx) -> Result<(), JobError> {
digest::send(cx.db(), self.user_id).await?;
Ok(())
}
}
fn register(&self, registry: &mut Registry) {
registry.add_job::<SendDigest>();
}
ctx.queue().push(&SendDigest { user_id: 7 }).await?;Jobs live in a QueueDriver: the database by default, or Redis with
the redis store. queue.mode = inline runs a job as it is pushed, for
tests and for an application without a worker.
Modules§
- migrations
- The queue schema, as a portable one-file migration.
Structs§
- Database
Queue - Jobs in the application’s database.
- Failed
Job - A job on the failed list.
- JobCx
- What a running job sees: the application’s services and its own attempt.
- JobFailed
- Announced when a job reaches the failed list.
- JobMeta
- What the worker reads from a payload before running it.
- JobReg
- A registered job: its name and how to run a payload of it. Built by
JobReg::ofand contributed throughQueueRegistry::add_job. - Options
- What
Queue::newtakes beside the driver and the jobs. - Queue
- The queue handle. Cheap to clone: every clone is the same queue.
- Queue
Count - How many jobs a queue holds.
- Queue
Module - The module that owns the
jobsandfailed_jobstables, listed among an application’s built-ins. - Queued
- A job as it waits or runs.
- Services
- The services a job runs against.
- Work
Options - How one
Workerruns. - Worker
- One worker loop over a
Queue.
Enums§
Constants§
- DEFAULT_
QUEUE - The queue a job lands on when it names none.
Traits§
- Job
- Work to run later. The struct is the payload: whatever it carries is stored as JSON and read back by the worker.
- Queue
Driver - Where jobs wait. Every method is one storage operation; the worker’s
rules live in
Worker. - Queue
Registry registry.add_job::<T>(): the typed way to contribute a job.
Functions§
- from_
config - The queue a deployment configured: the database by default, Redis for
the
redisstore. - time_
text