evoq_execution_context (evoq v1.14.1)

View Source

Execution context for command dispatch.

Tracks command execution state through the middleware pipeline, including retry attempts, consistency requirements, and metadata.

Summary

Functions

Check if retries are available.

Get a value from the context metadata.

Create a new execution context from a command.

Create a new execution context with options.

Put a value into the context metadata.

Attempt to retry the command. Returns {ok, NewContext} if retries remain, {error, too_many_attempts} otherwise.

Functions

can_retry(Evoq_execution_context)

-spec can_retry(#evoq_execution_context{command_id :: binary(),
                                        causation_id :: binary() | undefined,
                                        correlation_id :: binary() | undefined,
                                        aggregate_id :: binary(),
                                        aggregate_type :: atom(),
                                        store_id :: atom(),
                                        expected_version :: integer(),
                                        retry_attempts :: non_neg_integer(),
                                        consistency :: eventual | strong | {handlers, [atom()]},
                                        timeout :: pos_integer(),
                                        metadata :: map()}) ->
                   boolean().

Check if retries are available.

get(Key, Evoq_execution_context)

-spec get(atom(),
          #evoq_execution_context{command_id :: binary(),
                                  causation_id :: binary() | undefined,
                                  correlation_id :: binary() | undefined,
                                  aggregate_id :: binary(),
                                  aggregate_type :: atom(),
                                  store_id :: atom(),
                                  expected_version :: integer(),
                                  retry_attempts :: non_neg_integer(),
                                  consistency :: eventual | strong | {handlers, [atom()]},
                                  timeout :: pos_integer(),
                                  metadata :: map()}) ->
             term() | undefined.

Get a value from the context metadata.

new(Evoq_command)

-spec new(#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}) ->
             #evoq_execution_context{command_id :: binary(),
                                     causation_id :: binary() | undefined,
                                     correlation_id :: binary() | undefined,
                                     aggregate_id :: binary(),
                                     aggregate_type :: atom(),
                                     store_id :: atom(),
                                     expected_version :: integer(),
                                     retry_attempts :: non_neg_integer(),
                                     consistency :: eventual | strong | {handlers, [atom()]},
                                     timeout :: pos_integer(),
                                     metadata :: map()}.

Create a new execution context from a command.

new(Evoq_command, Opts)

-spec new(#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},
          map()) ->
             #evoq_execution_context{command_id :: binary(),
                                     causation_id :: binary() | undefined,
                                     correlation_id :: binary() | undefined,
                                     aggregate_id :: binary(),
                                     aggregate_type :: atom(),
                                     store_id :: atom(),
                                     expected_version :: integer(),
                                     retry_attempts :: non_neg_integer(),
                                     consistency :: eventual | strong | {handlers, [atom()]},
                                     timeout :: pos_integer(),
                                     metadata :: map()}.

Create a new execution context with options.

The store_id option determines which ReckonDB store to use. If not specified, falls back to the application env configuration.

put(Key, Value, Evoq_execution_context)

-spec put(atom(),
          term(),
          #evoq_execution_context{command_id :: binary(),
                                  causation_id :: binary() | undefined,
                                  correlation_id :: binary() | undefined,
                                  aggregate_id :: binary(),
                                  aggregate_type :: atom(),
                                  store_id :: atom(),
                                  expected_version :: integer(),
                                  retry_attempts :: non_neg_integer(),
                                  consistency :: eventual | strong | {handlers, [atom()]},
                                  timeout :: pos_integer(),
                                  metadata :: map()}) ->
             #evoq_execution_context{command_id :: binary(),
                                     causation_id :: binary() | undefined,
                                     correlation_id :: binary() | undefined,
                                     aggregate_id :: binary(),
                                     aggregate_type :: atom(),
                                     store_id :: atom(),
                                     expected_version :: integer(),
                                     retry_attempts :: non_neg_integer(),
                                     consistency :: eventual | strong | {handlers, [atom()]},
                                     timeout :: pos_integer(),
                                     metadata :: map()}.

Put a value into the context metadata.

retry(Evoq_execution_context)

-spec retry(#evoq_execution_context{command_id :: binary(),
                                    causation_id :: binary() | undefined,
                                    correlation_id :: binary() | undefined,
                                    aggregate_id :: binary(),
                                    aggregate_type :: atom(),
                                    store_id :: atom(),
                                    expected_version :: integer(),
                                    retry_attempts :: non_neg_integer(),
                                    consistency :: eventual | strong | {handlers, [atom()]},
                                    timeout :: pos_integer(),
                                    metadata :: map()}) ->
               {ok,
                #evoq_execution_context{command_id :: binary(),
                                        causation_id :: binary() | undefined,
                                        correlation_id :: binary() | undefined,
                                        aggregate_id :: binary(),
                                        aggregate_type :: atom(),
                                        store_id :: atom(),
                                        expected_version :: integer(),
                                        retry_attempts :: non_neg_integer(),
                                        consistency :: eventual | strong | {handlers, [atom()]},
                                        timeout :: pos_integer(),
                                        metadata :: map()}} |
               {error, too_many_attempts}.

Attempt to retry the command. Returns {ok, NewContext} if retries remain, {error, too_many_attempts} otherwise.