id_effect_jobs
Background jobs for id_effect services: a Postgres SKIP LOCKED queue on id_effect_sql,
workers with per-queue concurrency, retries with backoff and a dead state, unique keys, run_at,
and cron schedules that run once per cluster (ADR 0010 Amendment 6).
- Jobs are
#[derive(Schema)]structs implementingJob(a stableNAME, queue, priority,max_attempts, optionalUniqueKey, retrySchedule); the payload is stored asjsonb. JobQueueis the capability:enqueue/enqueue_at/enqueue_after,cancel,retry_now,stats,list.PgJobQueuestores jobs in the tableid_effect_jobs(schema:migrator(), tracked in_id_effect_jobs_migrations, orPgJobQueue::ensure_schema);MemoryJobQueuekeeps them in memory for tests.enqueue_in(&tx, job, opts, &clock)inserts with the caller's transaction, so the job commits or rolls back with the caller's work.Workerruns aJobRegistry's handlers: per-queue concurrency, a lease renewed by a heartbeat, rescue of crashed workers' jobs, retries untildead, and a drain on shutdown.
States: scheduled → running → succeeded, failed (awaiting a retry) → running …, dead, and
cancelled. Every time the queue reads comes from a WallClock, so tests run on virtual time.
Delivery is at least once: handlers must be idempotent.
use Arc;
use ;
use ;
use ;
let sent = new;
let s = clone;
let registry = new
.
.unwrap;
let exec = new;
let clock = anchored;
let store = new;
let env = hlist!;
let worker = new.queue;
let program = store
.enqueue
.flat_map;
let done = program.fork_root;
exec.run_until_stalled;
assert!;
assert_eq!;
let state: JobState = "dead".parse.unwrap;
assert!;
Tier platform: the Ledger reference app under examples/reference/ depends on it.