Temporalex.Activity (Temporalex v0.2.0)

Copy Markdown View Source

Defines activities that workflows can call.

defmodule MyApp.Activities.Payment do
  use Temporalex.Activity

  defactivity charge(amount), timeout: 30_000 do
    Stripe.charge(amount)
  end
end

Each defactivity generates two functions:

  1. charge(amount) — dispatch function called from workflow code. Sends {:execute_activity, type, input, opts} to the executor.

  2. __charge__/1 — implementation function called by the server when an activity task arrives. Public for direct use in tests.

The module also generates __temporal_activities__/0 returning [{name, opts}] for registration.

Summary

Functions

Define an activity with a name, optional options, and a body.

Functions

defactivity(head, opts \\ [], list)

(macro)

Define an activity with a name, optional options, and a body.

Options:

  • :timeout — schedule-to-close timeout in ms (default: 30_000)
  • :heartbeat_timeout — heartbeat timeout in ms
  • :retry_policy — retry configuration map
  • :local — when true, the dispatch function calls execute_local_activity/3 instead. Use for short, in-process operations (id generation, current time, lookups). Local activities are recorded in workflow history and survive worker crashes.
  • :start_to_close_timeout_ms — local activity timeout (default: 30_000)