middleware

package
v0.6.0-beta.202406210034 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 21, 2024 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EventMiddleware

func EventMiddleware(ctx context.Context) message.HandlerMiddleware

This middleware writes the command and event to the jsonl event store file

func PanicRecovererMiddleware

func PanicRecovererMiddleware(ctx context.Context) message.HandlerMiddleware

Recover from Go panic middleware. Based on Watermill Recoverer middleware.

The panic will be wrapped in a Flowpipe Error and set as a fatal error (non-retryable).

Types

type RecoveredPanicError

type RecoveredPanicError struct {
	V          interface{}
	Stacktrace string
}

Holds the recovered panic's error along with the stacktrace.

func (RecoveredPanicError) Error

func (p RecoveredPanicError) Error() string

type Retry

type Retry struct {
	Ctx context.Context

	// MaxRetries is maximum number of times a retry will be attempted.
	MaxRetries int

	// InitialInterval is the first interval between retries. Subsequent intervals will be scaled by Multiplier.
	InitialInterval time.Duration
	// MaxInterval sets the limit for the exponential backoff of retries. The interval will not be increased beyond MaxInterval.
	MaxInterval time.Duration
	// Multiplier is the factor by which the waiting interval will be multiplied between retries.
	Multiplier float64
	// MaxElapsedTime sets the time limit of how long retries will be attempted. Disabled if 0.
	MaxElapsedTime time.Duration
	// RandomizationFactor randomizes the spread of the backoff times within the interval of:
	// [currentInterval * (1 - randomization_factor), currentInterval * (1 + randomization_factor)].
	RandomizationFactor float64

	// OnRetryHook is an optional function that will be executed on each retry attempt.
	// The number of the current retry is passed as retryNum,
	OnRetryHook func(retryNum int, delay time.Duration)
}

Custom retry middleware. To be used with Go Channel pub/sub. We need to be able to ack the message after the retry > max retry. Otherwise the message will be re-delivered and and we end up in an infinite loop situation

The majority of this code is based on the Watermill Retry middleware.

func (Retry) Middleware

func (r Retry) Middleware(h message.HandlerFunc) message.HandlerFunc

Middleware function returns the Retry middleware.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL