Kathikon.Worker behaviour (Kathikon v0.2.1)

Copy Markdown View Source

Behaviour for Kathikon job workers.

Example

defmodule MyApp.EmailWorker do
  use Kathikon.Worker

  @impl true
  def perform(%Kathikon.Job{args: %{"to" => email}}) do
    MyApp.Mailer.deliver(email)
    :ok
  end
end

{:ok, _job} = Kathikon.insert(MyApp.EmailWorker, %{"to" => "user@example.com"})

Return values

  • :ok — success; result stored per result: :store | :discard

  • {:ok, result} — success with explicit result
  • {:error, reason} — failure; retry with backoff until max attempts, then dead-letter
  • {:discard, reason} — permanent discard (no retry)
  • {:retry, reason} — failure treated as retryable even when attempts remain
  • {:sleep, seconds} — defer without counting as failure

See docs/guides/workers.md.

Summary

Callbacks

perform(job)

@callback perform(job :: Kathikon.Job.t()) ::
  :ok
  | {:ok, term()}
  | {:error, term()}
  | {:discard, term()}
  | {:retry, term()}
  | {:sleep, pos_integer()}