Documentation
¶
Index ¶
- func RunCommand[T any](ctx context.Context, h *Handler, c command.Commander[T], msg T) error
- func RunQuery[T any, R any](ctx context.Context, h *Handler, q command.Querier[T, R], msg T) (R, error)
- type DeadlineGetter
- type DoneHandlerGetter
- type ErrorHandlerGetter
- type ExitOnErrorGetter
- type ExponentialBackoffStrategy
- type Handler
- type Logger
- type LoggerGetter
- type MaxRetriesGetter
- type MaxRunsGetter
- type Middleware
- type NoDelayStrategy
- type Option
- func WithConfigurator(i interface{}) Option
- func WithDeadline(d time.Time) Option
- func WithDeadlineSetter(s DeadlineGetter) Option
- func WithDoneHandler(d func(*Handler)) Option
- func WithDoneHandlerSetter(s DoneHandlerGetter) Option
- func WithErrorHandler(h func(error)) Option
- func WithErrorHandlerSetter(s ErrorHandlerGetter) Option
- func WithExitOnError(exit bool) Option
- func WithExitOnErrorSetter(s ExitOnErrorGetter) Option
- func WithLogger(l Logger) Option
- func WithLoggerSetter(s LoggerGetter) Option
- func WithMaxRetries(max int) Option
- func WithMaxRetriesSetter(s MaxRetriesGetter) Option
- func WithMaxRuns(max int) Option
- func WithMaxRunsSetter(s MaxRunsGetter) Option
- func WithMiddleware(mw ...Middleware) Option
- func WithNoTimeout() Option
- func WithRetryStrategy(s RetryStrategy) Option
- func WithRetryStrategySetter(s RetryStrategyGetter) Option
- func WithRunOnce(once bool) Option
- func WithRunOnceSetter(s RunOnceGetter) Option
- func WithTimeout(t time.Duration) Option
- func WithTimeoutSetter(s TimeoutGetter) Option
- type RetryStrategy
- type RetryStrategyGetter
- type RunOnceGetter
- type TimeoutGetter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RunCommand ¶
Types ¶
type DeadlineGetter ¶ added in v0.1.0
type DoneHandlerGetter ¶ added in v0.1.0
type DoneHandlerGetter interface {
GetDoneHandler() func(*Handler)
}
type ErrorHandlerGetter ¶ added in v0.1.0
type ErrorHandlerGetter interface {
GetErrorHandler() func(error)
}
type ExitOnErrorGetter ¶ added in v0.3.0
type ExitOnErrorGetter interface {
GetExitOnError() bool
}
type ExponentialBackoffStrategy ¶
type ExponentialBackoffStrategy struct {
// Base is the starting delay (e.g., 100ms)
Base time.Duration
// Factor is multiplied each iteration (e.g., 2 => 100ms, 200ms, 400ms, ...)
Factor float64
// Max is the maximum delay allowed (caps the exponential growth)
Max time.Duration
}
ExponentialBackoffStrategy implements a backoff strategy. Usage example:
WithRetryStrategy(ExponentialBackoffStrategy{
Base: 100 * time.Millisecond,
Factor: 2,
Max: 5 * time.Second,
})
func (ExponentialBackoffStrategy) SleepDuration ¶
func (e ExponentialBackoffStrategy) SleepDuration(attempt int, _ error) time.Duration
SleepDuration implements an exponential backoff with a cap at Max.
type Handler ¶
type Handler struct {
EntryID int
// contains filtered or unexported fields
}
Handler wraps configuration options so that we can later call a function with known behavior in terms of handling errors, rtries, timeouts, etc We do so by providing a Run method:
Run(ctx context.Context, fn func(context.Context) error)
This ensures consistent execution behavior
func NewHandler ¶
NewHandler constructs a Runner from various options, applying defaults if unset.
func (*Handler) ShouldStopOnErr ¶ added in v0.3.0
ShouldStopOnError returns whether execution should stop on first error
type LoggerGetter ¶ added in v0.1.0
type LoggerGetter interface {
GetLogger() Logger
}
type MaxRetriesGetter ¶ added in v0.1.0
type MaxRetriesGetter interface {
GetMaxRetries() int
}
type MaxRunsGetter ¶ added in v0.1.0
type MaxRunsGetter interface {
GetMaxRuns() int
}
type Middleware ¶ added in v0.3.0
Middleware defines a function that wraps/enhances the behavior of a handler function. It allows you to intercept and modify the execution of the function passed to Handler.Run (business logic) without changing its implementation. Each middleware receives the next function in the chain and returns a new function that can perform additional actions before or after calling the next function. This pattern enables composable concerns such as logging, telemetry, authentication, retry logic, in a clean and decoupled manner, similar to middleware in HTTP routers or RPC frameworks.
type NoDelayStrategy ¶
type NoDelayStrategy struct{}
NoDelayStrategy is a simple retry strategy that performs all retries immediately without waiting.
func (NoDelayStrategy) SleepDuration ¶
func (n NoDelayStrategy) SleepDuration(_ int, _ error) time.Duration
SleepDuration always returns zero, causing immediate retries.
type Option ¶
type Option func(*Handler)
func WithConfigurator ¶ added in v0.1.0
func WithConfigurator(i interface{}) Option
WithConfigurator sets multiple options from a single configuration struct that implements one or more Getter interfaces
func WithDeadline ¶
func WithDeadlineSetter ¶ added in v0.1.0
func WithDeadlineSetter(s DeadlineGetter) Option
func WithDoneHandler ¶
func WithDoneHandlerSetter ¶ added in v0.1.0
func WithDoneHandlerSetter(s DoneHandlerGetter) Option
func WithErrorHandler ¶
func WithErrorHandlerSetter ¶ added in v0.1.0
func WithErrorHandlerSetter(s ErrorHandlerGetter) Option
func WithExitOnError ¶ added in v0.3.0
WithExitOnError configures a runner to stop on first error
func WithExitOnErrorSetter ¶ added in v0.3.0
func WithExitOnErrorSetter(s ExitOnErrorGetter) Option
func WithLogger ¶
func WithLoggerSetter ¶ added in v0.1.0
func WithLoggerSetter(s LoggerGetter) Option
func WithMaxRetries ¶
func WithMaxRetriesSetter ¶ added in v0.1.0
func WithMaxRetriesSetter(s MaxRetriesGetter) Option
func WithMaxRuns ¶
func WithMaxRunsSetter ¶ added in v0.1.0
func WithMaxRunsSetter(s MaxRunsGetter) Option
func WithMiddleware ¶ added in v0.3.0
func WithMiddleware(mw ...Middleware) Option
func WithNoTimeout ¶ added in v0.3.0
func WithNoTimeout() Option
func WithRetryStrategy ¶
func WithRetryStrategy(s RetryStrategy) Option
WithRetryStrategy lets you define a custom retry/backoff approach
func WithRetryStrategySetter ¶ added in v0.1.0
func WithRetryStrategySetter(s RetryStrategyGetter) Option
func WithRunOnce ¶
func WithRunOnceSetter ¶ added in v0.1.0
func WithRunOnceSetter(s RunOnceGetter) Option
func WithTimeout ¶
func WithTimeoutSetter ¶ added in v0.1.0
func WithTimeoutSetter(s TimeoutGetter) Option
type RetryStrategy ¶
type RetryStrategy interface {
// SleepDuration returns how long to wait before the next retry attempt.
// The attempt index starts at 0, incrementing after each failure.
SleepDuration(attempt int, err error) time.Duration
}
RetryStrategy encapsulates the decision and delay between retries.
type RetryStrategyGetter ¶ added in v0.1.0
type RetryStrategyGetter interface {
GetRetryStrategy() RetryStrategy
}
type RunOnceGetter ¶ added in v0.1.0
type RunOnceGetter interface {
GetRunOnce() bool
}