scheduler

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Scheduler

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

Scheduler wraps robfig/cron and manages named tasks.

func New

func New(log *slog.Logger) *Scheduler

New creates a scheduler with the standard 5-field cron parser plus descriptors (@every, @daily, etc.).

func (*Scheduler) Add

func (s *Scheduler) Add(schedule, name string, fn TaskFunc) error

Add registers a named task with a cron expression. Returns an error if the cron expression is invalid.

func (*Scheduler) Run

func (s *Scheduler) Run(ctx context.Context) error

Run starts the cron engine and blocks until ctx is cancelled. On shutdown it waits for any running tasks to complete before returning.

func (*Scheduler) Tasks

func (s *Scheduler) Tasks() []Task

Tasks returns all registered tasks.

type Task

type Task struct {
	Name     string
	Schedule string
	Run      TaskFunc
}

Task is a named scheduled task with a cron expression.

type TaskFunc

type TaskFunc func(ctx context.Context) error

TaskFunc is a function executed on schedule.

Jump to

Keyboard shortcuts

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