Absurd.Task behaviour (absurd v0.2.0)

Copy Markdown View Source

Behaviour for application-defined durable tasks.

Persisted task names and queue names are explicit strings; Elixir module names are never used as durable protocol names implicitly.

Example

defmodule MyApp.SendEmail do
  use Absurd.Task,
    name: "send-email",
    queue: "io",
    default_max_attempts: 3

  @impl Absurd.Task
  def run(params, _context), do: {:ok, params}
end

Summary

Types

Compile-time metadata attached to a task module.

The explicit success or failure returned by a task callback.

Callbacks

Runs one attempt of a durable task.

Functions

Declares an application module as an Absurd task.

Types

metadata()

@type metadata() :: %{
  name: String.t(),
  queue: String.t() | nil,
  default_max_attempts: pos_integer() | nil,
  default_cancellation: keyword() | nil
}

Compile-time metadata attached to a task module.

result()

@type result() :: {:ok, Absurd.JSON.value()} | {:error, term()}

The explicit success or failure returned by a task callback.

Callbacks

run(params, context)

@callback run(params :: Absurd.JSON.value(), context :: Absurd.Context.t()) :: result()

Runs one attempt of a durable task.

Functions

__using__(options)

(macro)
@spec __using__(keyword()) :: Macro.t()

Declares an application module as an Absurd task.

:name is required. Optional registration defaults are :queue, :default_max_attempts, and :default_cancellation. A cancellation policy accepts :max_duration and :max_delay in seconds.