alepha@docs:~/docs/framework/reference/providers$
cat JobProvider.md | pretty1 min read
Last commit:
#JobProvider
#Import
typescript
1import { JobProvider } from "alepha/api/jobs";
#Overview
Coordinates cron and push jobs with a durable outbox table and a single
reconciliation sweep. The actual delivery channel (queue / direct) is
abstracted behind JobDispatcher, substituted by DI:
- DirectJobDispatcher (default, registered by
AlephaApiJobs) - runs the handler in-process right afterpush()returns. - QueueJobDispatcher (registered by
AlephaApiJobsQueue): sends the executionId throughAlephaQueueso a pool of workers can pick it up.
Push flow: push() → INSERT row (pending) → dispatcher.dispatch(jobName, id) worker → claim → UPDATE running → handler → DELETE/UPDATE on success → UPDATE error / scheduled (retry) on failure
Cron flow: scheduler tick → claim the instant → acquire lock → executeInline (no retry) → enqueue + dispatch (retry declared)
Sweep responsibilities (every sweepCron), one per status, declared in
sweepTable():
scheduledwithscheduledAt <= now→ pending + dispatchpendinguntouched forstaleThreshold→ re-dispatchrunningpast its lease → failed, then the retry policy
Trim runs on its own cron (trimCron, default hourly):
- per-job history trimmed beyond
keepLastSuccess/keepLastError - decoupled from sweep because trim cost scales with job count, not retry latency - running it every sweep is wasted work for most apps.