JobContext

interface JobContext

Execution context available to a handler as its receiver.

Klokka is at-least-once: a claimed job whose worker dies will run again. Use attempt, scheduledFor, and your own idempotency keys to make re-execution safe.

On the JVM every log line written while a handler runs carries the MDC entries klokka.jobId, klokka.kind, klokka.queue, klokka.attempt and, for schedule-emitted runs, klokka.scheduleId. They are propagated across suspension points, so handlers use their own logger and need no Klokka-specific one.

Properties

Link copied to clipboard
abstract val attempt: Int

1-based attempt number. 1 means this is not a retry.

Link copied to clipboard
abstract val enqueuedAt: Instant
Link copied to clipboard
abstract val jobId: JobId
Link copied to clipboard
abstract val kind: String
Link copied to clipboard
abstract val queue: QueueName
Link copied to clipboard
abstract val scheduledFor: Instant

The intended fire time, not the actual start time. For a schedule firing at 09:00 this is 09:00 even if execution starts at 09:00:02. Use it to answer "which window of data does this run cover" and to derive idempotency keys.

Link copied to clipboard
abstract val scheduleId: String?

Id of the recurring schedule that emitted this run (also set by triggerNow); null for directly enqueued jobs.

Functions

Link copied to clipboard
abstract suspend fun extendLease(by: Duration)

Renews this run's lease so that it now lasts by from the store's current time.

Link copied to clipboard
abstract suspend fun progress(fraction: Double)

Reports progress in 0.0..1.0 for the dashboard. Best-effort, cheap to call.