KlokkaRuntime
The engine: claims work from the store, executes registered handlers, orchestrates retries through CAS transitions, and emits JobEvents. Framework-free: klokka-ktor wires this to the Ktor application lifecycle, but any JVM main function can run it.
Lifecycle: construct, start inside a scope, drain on shutdown. Producer-role instances skip start entirely or start with role = Producer (no workers launched).
Properties
Functions
Graceful shutdown: stop claiming, wait up to KlokkaSettings.drainTimeout for in-flight jobs, then cancel stragglers and requeue them (transition Running to Enqueued with the fence). Safe to call without start (no-op) and at most once.
Persists a job due immediately, on JobOptions.queue if set, otherwise on JobType.queue. Returns the job id (existing id on uniqueKey dedup).
True when at least one recurring schedule is declared.
Declares a recurring schedule: payload is enqueued as a run of type every time schedule fires. Must be called before start, which registers all declared schedules with the store; only nodes that declare a schedule (and run workers) fire it, so declare recurring jobs on the worker fleet, not on producer-only nodes.
Launches the worker machinery as supervised children of scope: the claim loop, per-queue executors, the heartbeater, the retention sweeper, and (when schedules are declared) the scheduler loop that registers and fires them. No-op for KlokkaRole.Producer: a producer-only node neither runs jobs nor fires schedules. Idempotent: calling twice is an error.
Enqueues a run of the recurring schedule id immediately, without shifting the schedule's cadence. Respects the schedule's OverlapPolicy: with SkipIfRunning and a non-terminal run outstanding, this is an idempotent no-op returning that run's id.