Absurd.TaskCatalog behaviour (absurd v0.2.1)

Copy Markdown View Source

Validated task lookup for one worker-pool queue.

A catalog is built from an explicit list of Absurd.Task modules or from a module implementing this module's tasks/0 callback. Construction loads task metadata, requires a Absurd.Task.run/2 implementation, rejects queue mismatches, and rejects duplicate durable names before a worker can claim work.

Catalogs are immutable and local to their worker pool. There is no global module scan or runtime atom creation.

Examples

iex> {:ok, catalog} = Absurd.TaskCatalog.new([], "default")
iex> {catalog.queue, Absurd.TaskCatalog.size(catalog)}
{"default", 0}

An application catalog keeps a larger worker configuration focused:

defmodule MyApp.AbsurdTasks do
  @behaviour Absurd.TaskCatalog

  @impl Absurd.TaskCatalog
  def tasks, do: [MyApp.SendEmail, MyApp.GenerateInvoice]
end

Summary

Types

t()

An immutable durable-task lookup for one queue.

Callbacks

Returns the task modules supplied by an application catalog module.

Functions

Returns the module registered for a durable task name, or nil.

Builds and validates a catalog for queue.

Returns the number of registered task names.

Types

t()

@type t() :: %Absurd.TaskCatalog{
  queue: String.t(),
  tasks: %{optional(String.t()) => module()}
}

An immutable durable-task lookup for one queue.

Callbacks

tasks()

@callback tasks() :: [module()]

Returns the task modules supplied by an application catalog module.

Functions

fetch(task_catalog, task_name)

@spec fetch(t(), String.t()) :: module() | nil

Returns the module registered for a durable task name, or nil.

new(source, queue)

@spec new([module()] | module(), String.t()) ::
  {:ok, t()} | {:error, Absurd.Error.t()}

Builds and validates a catalog for queue.

source may be a list of task modules or a module implementing tasks/0. Task metadata with no queue inherits queue; explicit metadata must match it.

size(task_catalog)

@spec size(t()) :: non_neg_integer()

Returns the number of registered task names.