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