Core.Workers.Job (ServCore v0.1.0)

Copy Markdown View Source

Immutable job record that flows through the queue lifecycle.

Fields

  • :id — Assigned by the store (SQLite auto-increment or VM-local monotonic).
  • :payload — Arbitrary map supplied by the caller at submission time.
  • :status — One of :queued, :running, :done, :failed.
  • :attempt — Number of times this job has been claimed by a worker (starts at 0).
  • :max_attempts — Total claim attempts before the job is permanently failed (default: 3).
  • :retry_at — When the next retry is scheduled. nil unless job is waiting to retry.
  • :run_at — When a scheduled job should enter the in-memory queue. nil means immediate.
  • :inserted_at, :started_at, :finished_at — UTC timestamps for each lifecycle stage.

Lifecycle

:queued  :running  :done
                     :failed (retries_exhausted? or unrecoverable)
                     :queued (retry scheduled via backoff)

Summary

Functions

Calculates the next retry delay using exponential backoff. Returns milliseconds.

Deserialize a raw map (e.g. from a database row) into a %Job{} struct. Handles JSON string → map for payload/result and ISO8601 → DateTime.

Returns true if job has exhausted all retry attempts

Types

status()

@type status() :: :queued | :running | :done | :failed

t()

@type t() :: %Core.Workers.Job{
  attempt: non_neg_integer(),
  finished_at: DateTime.t() | nil,
  id: pos_integer() | nil,
  inserted_at: DateTime.t(),
  max_attempts: pos_integer(),
  payload: map(),
  result: map() | nil,
  retry_at: DateTime.t() | nil,
  run_at: DateTime.t() | nil,
  started_at: DateTime.t() | nil,
  status: status()
}

Functions

backoff_ms(job)

Calculates the next retry delay using exponential backoff. Returns milliseconds.

from_map(attrs)

Deserialize a raw map (e.g. from a database row) into a %Job{} struct. Handles JSON string → map for payload/result and ISO8601 → DateTime.

retries_exhausted?(job)

Returns true if job has exhausted all retry attempts