Kathikon.Storage.Mnesia (Kathikon v0.2.0)

Copy Markdown View Source

Mnesia implementation of Kathikon.Storage.

Tables:

  • :kathikon_jobs — job payloads
  • :kathikon_history — durable lifecycle events
  • :kathikon_batches — batch coordination records
  • :kathikon_schedules — built-in scheduler registrations

All state transitions use Mnesia transactions.

Summary

Functions

Atomically claims and starts up to limit jobs from queue.

Defers a running job to :scheduled with a durable history event.

Atomically updates batch counters for a finished child and returns completion intent.

Atomically transitions a parent to :waiting_for_children, inserts child jobs, and writes the batch record.

Functions

claim_and_start_available_jobs(queue, limit, claimant)

@spec claim_and_start_available_jobs(atom(), pos_integer(), map()) ::
  {:ok, [Kathikon.Job.t()]} | {:error, term()}

Atomically claims and starts up to limit jobs from queue.

Returns running jobs so callers never observe a stranded :claimed state.

defer_job(job_id, scheduled_at, metadata)

@spec defer_job(String.t(), DateTime.t(), map()) ::
  {:ok, Kathikon.Job.t()} | {:error, term()}

Defers a running job to :scheduled with a durable history event.

record_batch_child_finished(child)

@spec record_batch_child_finished(Kathikon.Job.t()) ::
  {:ok, :pending, map()}
  | {:ok, :complete, map(), Kathikon.Job.t()}
  | {:ok, :fail, map(), Kathikon.Job.t()}
  | {:error, term()}

Atomically updates batch counters for a finished child and returns completion intent.

start_batch(parent_job_id, child_jobs, batch_attrs)

@spec start_batch(String.t(), [Kathikon.Job.t()], map()) ::
  {:ok, map()} | {:error, term()}

Atomically transitions a parent to :waiting_for_children, inserts child jobs, and writes the batch record.