evoq_failure_context (evoq v1.14.1)

View Source

Failure context for tracking retry state.

Maintains state across retry attempts for event handlers. Used to implement sophisticated retry strategies with exponential backoff, jitter, and dead letter handling.

Summary

Functions

Get the current attempt number.

Get the duration since first failure.

Get the error that caused the failure.

Get the event that failed.

Get the handler module.

Increment the attempt counter and update timestamp.

Create a new failure context.

Add stacktrace to the context.

Functions

get_attempt(Evoq_failure_context)

-spec get_attempt(#evoq_failure_context{handler_module :: atom(),
                                        event :: map(),
                                        error :: term(),
                                        attempt_number :: pos_integer(),
                                        first_failure_at :: integer(),
                                        last_failure_at :: integer(),
                                        stacktrace :: list()}) ->
                     pos_integer().

Get the current attempt number.

get_duration(Evoq_failure_context)

-spec get_duration(#evoq_failure_context{handler_module :: atom(),
                                         event :: map(),
                                         error :: term(),
                                         attempt_number :: pos_integer(),
                                         first_failure_at :: integer(),
                                         last_failure_at :: integer(),
                                         stacktrace :: list()}) ->
                      non_neg_integer().

Get the duration since first failure.

get_error(Evoq_failure_context)

-spec get_error(#evoq_failure_context{handler_module :: atom(),
                                      event :: map(),
                                      error :: term(),
                                      attempt_number :: pos_integer(),
                                      first_failure_at :: integer(),
                                      last_failure_at :: integer(),
                                      stacktrace :: list()}) ->
                   term().

Get the error that caused the failure.

get_event(Evoq_failure_context)

-spec get_event(#evoq_failure_context{handler_module :: atom(),
                                      event :: map(),
                                      error :: term(),
                                      attempt_number :: pos_integer(),
                                      first_failure_at :: integer(),
                                      last_failure_at :: integer(),
                                      stacktrace :: list()}) ->
                   map().

Get the event that failed.

get_handler(Evoq_failure_context)

-spec get_handler(#evoq_failure_context{handler_module :: atom(),
                                        event :: map(),
                                        error :: term(),
                                        attempt_number :: pos_integer(),
                                        first_failure_at :: integer(),
                                        last_failure_at :: integer(),
                                        stacktrace :: list()}) ->
                     atom().

Get the handler module.

increment(Evoq_failure_context)

-spec increment(#evoq_failure_context{handler_module :: atom(),
                                      event :: map(),
                                      error :: term(),
                                      attempt_number :: pos_integer(),
                                      first_failure_at :: integer(),
                                      last_failure_at :: integer(),
                                      stacktrace :: list()}) ->
                   #evoq_failure_context{handler_module :: atom(),
                                         event :: map(),
                                         error :: term(),
                                         attempt_number :: pos_integer(),
                                         first_failure_at :: integer(),
                                         last_failure_at :: integer(),
                                         stacktrace :: list()}.

Increment the attempt counter and update timestamp.

new(HandlerModule, Event, Error)

-spec new(atom(), map(), term()) ->
             #evoq_failure_context{handler_module :: atom(),
                                   event :: map(),
                                   error :: term(),
                                   attempt_number :: pos_integer(),
                                   first_failure_at :: integer(),
                                   last_failure_at :: integer(),
                                   stacktrace :: list()}.

Create a new failure context.

with_stacktrace(Stacktrace, Evoq_failure_context)

-spec with_stacktrace(list(),
                      #evoq_failure_context{handler_module :: atom(),
                                            event :: map(),
                                            error :: term(),
                                            attempt_number :: pos_integer(),
                                            first_failure_at :: integer(),
                                            last_failure_at :: integer(),
                                            stacktrace :: list()}) ->
                         #evoq_failure_context{handler_module :: atom(),
                                               event :: map(),
                                               error :: term(),
                                               attempt_number :: pos_integer(),
                                               first_failure_at :: integer(),
                                               last_failure_at :: integer(),
                                               stacktrace :: list()}.

Add stacktrace to the context.