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 replaces the input Selector's logger with a different one, using the input slog.Handler.
If the input logger is nil, the Selector's logger will be set to be a no-op.
If the input Selector is nil or a no-op Selector, a no-op Selector is returned.
If the input Selector is a valid Selector, then its logger is replaced with a new one using the input handler.
Otherwise, the Selector is returned as-is.
func AddMetrics ¶
AddMetrics replaces the input Selector's metrics, using the input Metrics interface.
If the input metrics is nil, the Selector's metrics will be set to be a no-op.
If the input Selector is nil or a no-op Selector, a no-op Selector is returned.
If the input Selector is a valid Selector, then its metrics collector is replaced with the input one.
Otherwise, the Selector is returned as-is.
func AddTraces ¶
AddTraces replaces the input Selector's tracer with a different one, using the input trace.Tracer.
If the input tracer is nil, the Selector's tracer will be set to be a no-op.
If the input Selector is nil or a no-op Selector, a no-op Selector is returned.
If the input Selector is a valid Selector, then its tracer is replaced with the input one.
Otherwise, the Selector is returned as-is.