Expand description
A durable job queue for Tablo apps, in the app’s own database, and the queued auth mail built on it.
A job enqueued through a write’s transaction commits with that write or not at all, so “the
invitation exists” and “its mail will go out” cannot disagree. A Worker runs the queue
against a panel’s context, and any number of workers can share it. It is built on Tablo’s
public API alone (ADR-0041).
use serde::{Deserialize, Serialize};
use tablo_jobs::{Job, Worker, enqueue};
use topcoat::context::Cx;
#[derive(Serialize, Deserialize)]
struct SendInvitation {
invitation: u64,
}
impl Job for SendInvitation {
const KIND: &'static str = "send-invitation";
async fn run(self, cx: &Cx) -> topcoat::Result<()> {
// Load the invitation, and mail it unless it is gone.
Ok(())
}
}
// Inside the transaction that writes the invitation:
enqueue(&SendInvitation { invitation: id }).exec(tx).await?;
// In the worker process, or beside the server:
Worker::new(panel)?
.register::<SendInvitation>()
.drain()
.await?;The Db registers QueuedJob and JobSchedule: list them in the app’s
models!, as
tablo::models!(Post, tablo::jobs::QueuedJob, tablo::jobs::JobSchedule).
Structs§
- Auth
Mail Queue - Queues the letters a panel’s auth sends, for a
Workerwithauth_mailto send. - Enqueue
- A job on its way to the queue, from
enqueue: set its delay or its dedupe key, thenexecit. - JobSchedule
- When a recurring job next falls due: one row per schedule, shared by every worker.
- Queued
Job - One unit of background work, written by
enqueueand run by aWorker. - Worker
- Runs a panel’s queued jobs: claims the due ones, runs each with a timeout against the panel’s
context, and retries a failure with backoff.
Enums§
Traits§
- Job
- A kind of background work, whose fields are its payload.