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 ControlAwareCommander
- type DeadlineGetter
- type DoneHandlerGetter
- type ErrorHandlerGetter
- type ExecutionControl
- type ExitOnErrorGetter
- type ExponentialBackoffStrategy
- type Handler
- type Logger
- type LoggerGetter
- type ManualExecutionControl
- func (c *ManualExecutionControl) Cancel(cause error)
- func (c *ManualExecutionControl) CancelCause() error
- func (c *ManualExecutionControl) Done() <-chan struct{}
- func (c *ManualExecutionControl) Pause()
- func (c *ManualExecutionControl) Resume()
- func (c *ManualExecutionControl) WaitIfPaused(ctx context.Context) error
- 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 WithExecutionControl(control ExecutionControl) 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 RetryDecider
- type RetryDecision
- type RetryStrategy
- type RetryStrategyGetter
- type RunOnceGetter
- type TimeoutGetter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RunCommand ¶
Types ¶
type ControlAwareCommander ¶ added in v0.15.0
type ControlAwareCommander[T any] interface { ExecuteWithControl(ctx context.Context, msg T, ctl ExecutionControl) error }
ControlAwareCommander extends command execution with execution-control support.
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 ExecutionControl ¶ added in v0.15.0
type ExecutionControl interface {
WaitIfPaused(ctx context.Context) error
Done() <-chan struct{}
CancelCause() error
}
ExecutionControl provides cooperative execution control for handlers.
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) Decide ¶ added in v0.15.0
func (e ExponentialBackoffStrategy) Decide(attempt int, err error) RetryDecision
Decide retries with exponential delay.
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 ManualExecutionControl ¶ added in v0.15.0
type ManualExecutionControl struct {
// contains filtered or unexported fields
}
ManualExecutionControl is a cooperative control implementation useful for orchestration and tests.
func NewManualExecutionControl ¶ added in v0.15.0
func NewManualExecutionControl() *ManualExecutionControl
NewManualExecutionControl creates a control that can be paused/resumed/canceled manually.
func (*ManualExecutionControl) Cancel ¶ added in v0.15.0
func (c *ManualExecutionControl) Cancel(cause error)
Cancel marks control as done and optionally records a cause.
func (*ManualExecutionControl) CancelCause ¶ added in v0.15.0
func (c *ManualExecutionControl) CancelCause() error
func (*ManualExecutionControl) Done ¶ added in v0.15.0
func (c *ManualExecutionControl) Done() <-chan struct{}
func (*ManualExecutionControl) Pause ¶ added in v0.15.0
func (c *ManualExecutionControl) Pause()
Pause blocks future WaitIfPaused calls until Resume is called.
func (*ManualExecutionControl) Resume ¶ added in v0.15.0
func (c *ManualExecutionControl) Resume()
Resume unblocks waiters created by Pause.
func (*ManualExecutionControl) WaitIfPaused ¶ added in v0.15.0
func (c *ManualExecutionControl) WaitIfPaused(ctx context.Context) error
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) Decide ¶ added in v0.15.0
func (n NoDelayStrategy) Decide(_ int, _ error) RetryDecision
Decide always retries immediately.
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 WithExecutionControl ¶ added in v0.15.0
func WithExecutionControl(control ExecutionControl) Option
WithExecutionControl configures cooperative execution control for a handler.
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 RetryDecider ¶ added in v0.15.0
type RetryDecider interface {
Decide(attempt int, err error) RetryDecision
}
RetryDecider is an optional richer strategy contract.
type RetryDecision ¶ added in v0.15.0
RetryDecision captures retry decision outputs for one failed attempt.
func DecideRetry ¶ added in v0.15.0
func DecideRetry(strategy RetryStrategy, attempt int, err error) RetryDecision
DecideRetry returns a decision from a strategy, preferring RetryDecider when available.
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
}