Temporalex.Workflow.API (Temporalex v0.3.2)

Copy Markdown View Source

Workflow primitives available from executor-owned workflow processes.

Summary

Functions

Block until a child workflow (started via start_child_workflow/3) completes. Returns its result tuple — {:ok, value}, {:error, _}, or {:cancelled, _}.

Request cancellation of a child workflow started by this workflow.

Start a child workflow and block until it completes.

Schedule a local activity — runs in-process on this worker rather than via the Temporal task queue, with durability provided by a history marker.

Send a signal to a child workflow that was started by this workflow.

Start a child workflow and return a handle as soon as the child is started by Temporal (does NOT block until completion).

Functions

await_child_workflow(child_handle)

Block until a child workflow (started via start_child_workflow/3) completes. Returns its result tuple — {:ok, value}, {:error, _}, or {:cancelled, _}.

If the child has already completed, returns the cached result immediately. Otherwise blocks the calling thread until the child reaches a terminal state.

cancel_child_workflow(handle_or_id, opts \\ [])

Request cancellation of a child workflow started by this workflow.

Accepts either a Temporalex.ChildHandle or a raw workflow id string.

Cancellation is durable and the call blocks until Temporal confirms the cancel request has been delivered. The child receives the cancel via its API.cancelled?/0 flag — it's the child's responsibility to observe and act on it.

cancelled?()

context!()

context_key()

deprecate_patch(patch_id)

execute_activity(type, input, opts \\ [])

execute_child_workflow(workflow, input, opts \\ [])

Start a child workflow and block until it completes.

workflow may be a module that uses Temporalex.Workflow (its __workflow_type__/0 is consulted) or a workflow type string.

Options:

  • :workflow_id (required) — child workflow identifier
  • :task_queue — defaults to the parent's task queue
  • :execution_timeout_ms, :run_timeout_ms, :task_timeout_ms
  • :retry_policy — keyword list, same shape as activity retry policies
  • :parent_close_policy:terminate (default), :abandon, :request_cancel
  • :workflow_id_reuse_policy:allow_duplicate (default), :allow_duplicate_failed_only, :reject_duplicate, :terminate_if_running

Returns {:ok, result} on completion, {:error, %Temporalex.ChildWorkflowFailure{...}} on child failure or start failure, {:cancelled, ...} on cancellation.

execute_local_activity(type, input, opts \\ [])

Schedule a local activity — runs in-process on this worker rather than via the Temporal task queue, with durability provided by a history marker.

Faster than regular activities for short, deterministic work that doesn't need cross-worker scheduling. The activity body still runs in the activity task supervisor; Temporal Core records a marker so replay is correct.

install_context(context)

now()

parallel(funs)

patched?(patch_id)

phase(initial_state, opts)

publish_state(state)

random()

signal_child_workflow(handle_or_id, signal_name, args \\ [], opts \\ [])

Send a signal to a child workflow that was started by this workflow.

workflow_id must match the workflow_id you used in execute_child_workflow/3. The signal is sent durably — the call blocks until Temporal confirms delivery (or fails).

Returns :ok on successful delivery, {:error, %Temporalex.ApplicationError{}} if the target workflow doesn't exist or the signal can't be delivered.

This is a "fire and confirm delivery" primitive: the signal handler in the child runs asynchronously to the parent; success only means Temporal has accepted the signal for delivery.

sleep(duration_ms)

start_child_workflow(workflow, input, opts \\ [])

Start a child workflow and return a handle as soon as the child is started by Temporal (does NOT block until completion).

Use the returned Temporalex.ChildHandle to signal, cancel, or await_child_workflow/1 for the eventual result.

Returns {:ok, %Temporalex.ChildHandle{}} on successful start, or {:error, %Temporalex.ChildWorkflowFailure{}} if the start fails.

update_state(fun)

upsert_search_attributes(attrs)

uuid4()

wait_for_signal(name)

workflow_info()