Documentation ¶
Index ¶
- func WithLocation(loc *time.Location) 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 WithSchedule(cronString string) cfg.Option[Config]
- func WithTrace(tracer trace.Tracer) cfg.Option[Config]
- type Config
- type CronSchedule
- type Metrics
- type Scheduler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithLocation ¶
WithLocation configures the Scheduler with the input time.Location.
This call returns a cfg.NoOp cfg.Option if the input time.Location is nil.
func WithLogHandler ¶
WithLogHandler decorates the Scheduler with logging using the input log handler.
func WithLogger ¶
WithLogger decorates the Scheduler with the input logger.
func WithMetrics ¶
WithMetrics decorates the Scheduler with the input metrics registry.
func WithSchedule ¶
WithSchedule configures the Scheduler with the input cron string.
This call returns a cfg.NoOp cfg.Option if the input cron string is empty.
Types ¶
type CronSchedule ¶
type CronSchedule struct { // Loc will localize the times to a certain region or geolocation. Loc *time.Location // Schedule describes the schedule frequency definition, with different cron schedule elements. Schedule cronlex.Schedule }
CronSchedule represents a basic implementation of a Scheduler, following the cron schedule specification.
It is composed of a time.Location specifier, as well as a cronlex.Schedule definition.
type Metrics ¶
type Metrics interface {
// IncSchedulerNextCalls increases the count of Next calls, by the Scheduler.
IncSchedulerNextCalls()
}
Metrics describes the actions that register Scheduler-related metrics.
type Scheduler ¶
type Scheduler interface { // Next calculates and returns the following scheduled time, from the input time.Time. Next(ctx context.Context, now time.Time) time.Time }
Scheduler describes the capabilities of a cron job scheduler. Its sole responsibility is to provide the timestamp for the next job's execution, after calculating its frequency from its configuration.
Scheduler exposes one method, Next, that takes in a context.Context and a time.Time. It is implied that the input time is the time.Now value, however it is open to any input that the caller desires to pass to it. The returned time.Time value must always be the following occurrence according to the schedule, in the context of the input time.
Implementations of Next should take into consideration the cron specification; however the interface allows a custom approach to the scheduler, especially if added functionality is necessary (e.g. frequency overriding schedulers, dynamic frequencies, and pipeline-approaches where the frequency is evaluated after a certain check).
func AddLogs ¶
AddLogs decorates the input Scheduler with logging, using the input slog.Handler.
If the input Scheduler is nil or a no-op Scheduler, a no-op Scheduler 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 Scheduler is already a logged Scheduler, then this logged Scheduler is returned with the new handler as its logger's handler.
Otherwise, the Scheduler is decorated with logging within a custom type that implements Scheduler.
func AddMetrics ¶
AddMetrics decorates the input Scheduler with metrics, using the input Metrics interface.
If the input Scheduler is nil or a no-op Scheduler, a no-op Scheduler is returned. If the input Metrics is nil or if it is a no-op Metrics interface, then the input Scheduler is returned as-is.
If the input Scheduler is already a Scheduler with metrics, then this Scheduler with metrics is returned with the new Metrics interface configured in place of the former.
Otherwise, the Scheduler is decorated with metrics within a custom type that implements Scheduler.
func AddTraces ¶
AddTraces decorates the input Scheduler with tracing, using the input trace.Tracer.
If the input Scheduler is nil or a no-op Scheduler, a no-op Scheduler is returned. If the input trace.Tracer is nil, then the input Scheduler is returned as-is.
If the input Scheduler is already a Scheduler with tracing, then this Scheduler with tracing is returned with the new trace.Tracer configured in place of the former.
Otherwise, the Scheduler is decorated with tracing within a custom type that implements Scheduler.