Documentation ¶
Index ¶
- Constants
- Variables
- func WithBlock() cfg.Option[Config]
- func WithExecutors(executors ...executor.Executor) cfg.Option[Config]
- func WithLogHandler(handler slog.Handler) cfg.Option[Config]
- func WithLogger(logger *slog.Logger) cfg.Option[Config]
- func WithMetrics(m Metrics) cfg.Option[Config]
- func WithTimeout(dur time.Duration) cfg.Option[Config]
- func WithTrace(tracer trace.Tracer) cfg.Option[Config]
- type Config
- type Metrics
- type Selector
Constants ¶
const ( ErrEmpty = errs.Kind("empty") ErrExecutorsList = errs.Entity("executors list") )
Variables ¶
var ErrEmptyExecutorsList = errs.WithDomain(errSelectorDomain, ErrEmpty, ErrExecutorsList)
Functions ¶
func WithBlock ¶
WithBlock configures the Selector to block (wait) for the underlying executor.Executor to complete the task.
By default, the returned Selector from New is a non-blocking Selector. It mostly relies on the setup of the components to at least register the error as metrics or logs, but Exec calls return nil errors if the local context times out.
WithBlock waits until the execution is done, so an accurate error value is returned from the Selector.
func WithExecutors ¶
WithExecutors configures the Selector with the input executor.Executor(s).
This call returns a cfg.NoOp cfg.Option if the input set of executor.Executor is empty, or contains only nil and / or no-op executor.Executor.
func WithLogHandler ¶
WithLogHandler decorates the Selector with logging using the input log handler.
func WithLogger ¶
WithLogger decorates the Selector with the input logger.
func WithMetrics ¶
WithMetrics decorates the Selector with the input metrics registry.
func WithTimeout ¶
WithTimeout configures a (non-blocking) Selector to wait a certain duration before detaching of the executable task, before continuing to select the next one.
By default, the local context timeout is set to one second. Any negative or zero duration values result in a cfg.NoOp cfg.Option being returned.
Types ¶
type Metrics ¶
type Metrics interface { // IncSelectorSelectCalls increases the count of Select calls, by the Selector. IncSelectorSelectCalls() // IncSelectorSelectErrors increases the count of Select call errors, by the Selector. IncSelectorSelectErrors() }
Metrics describes the actions that register Selector-related metrics.
type Selector ¶
type Selector interface { // Next picks up the following scheduled job to execute from its configured (set of) executor.Executor, and // calls its Exec method. // // This call also imposes a minimum step duration of 50ms, to ensure that early-runs are not executed twice due to the // nature of using clocks in Go. This sleep is deferred to come in after the actual execution of the job. // // The Selector allows multiple executor.Executor to be configured, and multiple executor.Executor can share similar // execution times. If that is the case, the executor is launched in an executor.Multi call. // // The error returned from a Next call is the error raised by the executor.Executor's Exec call. Next(ctx context.Context) error }
Selector describes the capabilities of a cron selector, which picks up the next job to execute (out of a set of executor.Executor)
Implementations of Selector must focus on the logic within its only method, Next, that will set the strategy to picking up the following job to run. The default implementation looks for the nearest job (in time) to execute, with support for multiple executions in one-go.
Custom implementations could, for example, check for preconditions, run clean-up jobs, and more.
The runtime of a Selector depends on the input context.Context when calling its Next method, as it can be used to signal cancellation or used for timeouts.
func AddLogs ¶
AddLogs decorates the input Selector with logging, using the input slog.Handler.
If the input Selector is nil or a no-op Selector, a no-op Selector is returned. If the input slog.Handler is nil or a no-op handler, then a default slog.Handler is configured (a text handler printing to standard-error)
If the input Selector is already a logged Selector, then this logged Selector is returned with the new handler as its logger's handler.
Otherwise, the Selector is decorated with logging within a custom type that implements Selector.
func AddMetrics ¶
AddMetrics decorates the input Selector with metrics, using the input Metrics interface.
If the input Selector is nil or a no-op Selector, a no-op Selector is returned. If the input Metrics is nil or if it is a no-op Metrics interface, then the input Selector is returned as-is.
If the input Selector is already a Selector with metrics, then this Selector with metrics is returned with the new Metrics interface configured in place of the former.
Otherwise, the Selector is decorated with metrics within a custom type that implements Selector.
func AddTraces ¶
AddTraces decorates the input Selector with tracing, using the input trace.Tracer.
If the input Selector is nil or a no-op Selector, a no-op Selector is returned. If the input trace.Tracer is nil, then the input Selector is returned as-is.
If the input Selector is already a Selector with tracing, then this Selector with tracing is returned with the new trace.Tracer configured in place of the former.
Otherwise, the Selector is decorated with tracing within a custom type that implements Selector.