schedule

package
v0.0.0-...-9cb5758 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 6, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithLocation

func WithLocation(loc *time.Location) cfg.Option[Config]

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

func WithLogHandler(handler slog.Handler) cfg.Option[Config]

WithLogHandler decorates the Scheduler with logging using the input log handler.

func WithLogger

func WithLogger(logger *slog.Logger) cfg.Option[Config]

WithLogger decorates the Scheduler with the input logger.

func WithMetrics

func WithMetrics(m Metrics) cfg.Option[Config]

WithMetrics decorates the Scheduler with the input metrics registry.

func WithSchedule

func WithSchedule(cronString string) cfg.Option[Config]

WithSchedule configures the Scheduler with the input cron string.

This call returns a cfg.NoOp cfg.Option if the input cron string is empty.

func WithTrace

func WithTrace(tracer trace.Tracer) cfg.Option[Config]

WithTrace decorates the Scheduler with the input trace.Tracer.

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

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.

func (CronSchedule) Next

func (s CronSchedule) Next(_ context.Context, t time.Time) time.Time

Next calculates and returns the following scheduled time, from the input time.Time.

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

func AddLogs(s Scheduler, handler slog.Handler) Scheduler

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

func AddMetrics(s Scheduler, m Metrics) Scheduler

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

func AddTraces(s Scheduler, tracer trace.Tracer) Scheduler

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.

func New

func New(options ...cfg.Option[Config]) (Scheduler, error)

New creates a Scheduler with the input cfg.Option(s), also returning an error if raised.

Creating a Scheduler requires the caller to provide at least a cron string, using the WithSchedule option.

If a time.Location is not specified with the WithLocation option, then time.Local is used.

func NoOp

func NoOp() Scheduler

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL