Skip to main content

Module jobs

Module jobs 

Source
Available on crate feature jobs only.
Expand description

Background job queue for one-shot, fire-and-forget work triggered from request handlers — e.g. “send a confirmation email after signup” — without blocking the response.

Two flavors:

  • JobQueue — an in-memory worker pool. Simple and dependency-free, but queued and retrying jobs are lost if the process crashes or restarts.
  • PersistentJobQueue (requires a model-sqlite / model-postgres / model-mysql feature) — persists jobs via the model layer so pending and retrying jobs survive a restart.

§Example

use rust_web_server::jobs::JobQueue;

let queue = JobQueue::new(4); // 4 worker threads
queue.submit(|| {
    println!("sending welcome email...");
    Ok(())
});
queue.join(); // wait for in-flight jobs to finish (tests/shutdown only)

Structs§

JobQueue
An in-memory background job queue backed by a fixed-size worker pool.
PersistentJobQueuemodel-mysql or model-postgres or model-sqlite
A job queue backed by the model layer (model-sqlite / model-postgres / model-mysql): jobs are written to a rws_jobs table before being acknowledged, so pending and retrying jobs survive a process crash or restart.

Traits§

Job
A unit of background work.