scheduler

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package scheduler provides declarative task scheduling support, backed by a robfig/cron adapter, for the Helix framework.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidCron is returned when a cron expression is malformed.
	ErrInvalidCron = errors.New("scheduler: invalid cron expression")

	// ErrJobNotFound is returned when a requested job does not exist.
	ErrJobNotFound = errors.New("scheduler: job not found")
)

Functions

func WrapError

func WrapError(name string, fn func() error) func()

WrapError wraps a func() error as func(), logging non-nil errors via slog. The job name is included as a structured slog field for observability.

func WrapSkipIfBusy

func WrapSkipIfBusy(fn func()) func()

WrapSkipIfBusy wraps fn so concurrent invocations are skipped.

Types

type CronExpression

type CronExpression = string

CronExpression is a standard 5-field cron expression or a robfig @-shortcut. Examples: "0 0 * * *" (daily midnight), "@every 1h", "@hourly".

type Job

type Job struct {
	// Name uniquely identifies the job for logging and error reporting.
	Name string
	// Expr is the cron schedule expression.
	Expr CronExpression
	// Fn is the function to invoke on schedule.
	Fn func()
	// AllowConcurrent opt-in disables the default skip-lock; future: distributed lock.
	AllowConcurrent bool
}

Job is a named task to be executed on a cron schedule.

type ScheduledJobProvider

type ScheduledJobProvider interface {
	ScheduledJobs() []Job
}

ScheduledJobProvider exposes cron jobs declared by a Helix component.

Components can use this runtime interface with methods documented by //helix:scheduled comments today; future code generation can derive the implementation from those comments automatically.

type Scheduler

type Scheduler interface {
	// Register adds a job to the scheduler. Returns ErrInvalidCron if the expression is invalid.
	Register(job Job) error
	// Start begins the background cron runner (non-blocking).
	Start()
	// Stop halts the scheduler, waiting for all running jobs to complete.
	Stop(ctx context.Context)
	// OnStart implements core.Lifecycle — starts the scheduler on application start.
	OnStart() error
	// OnStop implements core.Lifecycle — stops the scheduler on application shutdown.
	OnStop() error
}

Scheduler manages cron job registration and execution.

func NewScheduler

func NewScheduler() Scheduler

NewScheduler returns a new Scheduler backed by robfig/cron v3.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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