evoq_pm_instance (evoq v1.30.1)

View Source

Process manager instance GenServer.

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

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 | {ok, [{ok, non_neg_integer(), [map()]} | {error, term()}]} | {error, term()}.

Handle an event.

{ok, Results} carries one entry per command the process manager dispatched, in order, plus one per compensating command if a dispatch failed, so the list can be shorter than the commands the PM returned.

start_link(PMModule, ProcessId, Config)

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

Start a PM instance.