Documentation
¶
Overview ¶
Package worker runs a service worker loop with observability and back-off for no work found.
It is used by various `ex` packages internally, and can be used for any regular work your service might need to do, such as consuming queue-like data sources.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrShouldBackoff = errors.New("should back off")
Functions ¶
Types ¶
type Config ¶
type Config struct {
Name string
// NoWorkBackoff is the backoff strategy to use if the WorkFunc indicates a backoff should happen
NoWorkBackOff backoff.BackOff
// MaxWorkTime is the duration after which the context passed to the WorkFunc will be cancelled.
MaxWorkTime time.Duration
// MinWorkTime is the minimum duration each work loop can take. The WorkFunc will not be invoked any sooner
// than the last invocation and MinWorkTime. This can be used to throttle a busy worker.
MinWorkTime time.Duration
// WorkFunc should return ErrShouldBackoff if it wants to back off, or set BackoffOnAllErrors
WorkFunc func(ctx context.Context) error
// If backoff is desired for any returned error
BackoffOnAllErrors bool
// contains filtered or unexported fields
}
Click to show internal directories.
Click to hide internal directories.