evoq_pm_instance (evoq v1.14.1)

View Source

Process manager instance GenServer.

Represents a single running instance of a process manager (saga). Each instance: - Has a unique process ID (correlation ID) - Maintains its own state - Handles events and dispatches commands - Supports saga compensation on failures

Summary

Functions

Trigger compensation for a failed command.

Get the current state.

Functions

compensate(Pid, Evoq_command)

-spec compensate(pid(),
                 #evoq_command{command_id :: binary() | undefined,
                               command_type :: atom() | undefined,
                               aggregate_type :: atom() | undefined,
                               aggregate_id :: binary() | undefined,
                               payload :: map(),
                               metadata :: map(),
                               causation_id :: binary() | undefined,
                               correlation_id :: binary() | undefined,
                               idempotency_key :: binary() | undefined}) ->
                    {ok,
                     [#evoq_command{command_id :: binary() | undefined,
                                    command_type :: atom() | undefined,
                                    aggregate_type :: atom() | undefined,
                                    aggregate_id :: binary() | undefined,
                                    payload :: map(),
                                    metadata :: map(),
                                    causation_id :: binary() | undefined,
                                    correlation_id :: binary() | undefined,
                                    idempotency_key :: binary() | undefined}]} |
                    skip.

Trigger compensation for a failed command.

get_state(Pid)

-spec get_state(pid()) -> {ok, term()}.

Get the current state.

handle_event(Pid, Event, Metadata)

-spec handle_event(pid(), map(), map()) -> ok | {error, term()}.

Handle an event.

start_link(PMModule, ProcessId, Config)

-spec start_link(atom(), binary(), map()) -> {ok, pid()} | {error, term()}.

Start a PM instance.