scheduler

package
v0.0.0-...-d771ed5 Latest Latest
Warning

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

Go to latest
Published: May 29, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package scheduler runs recurring background jobs at fixed intervals.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Job

type Job struct {
	// Name is used in log output.
	Name string
	// Interval is how often the job runs.
	Interval time.Duration
	// Fn is the work to perform. It receives a context that is cancelled when
	// the scheduler is stopped.
	Fn func(ctx context.Context)
}

Job describes a recurring background task.

type Scheduler

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

Scheduler runs a set of Jobs at their configured intervals. Jobs run sequentially within their own goroutine; they do not block each other.

func New

func New(logger *slog.Logger) *Scheduler

New creates a Scheduler.

func (*Scheduler) Add

func (s *Scheduler) Add(j Job)

Add registers a job. Must be called before Start.

func (*Scheduler) Jobs

func (s *Scheduler) Jobs() []Job

Jobs returns a snapshot of all registered jobs.

func (*Scheduler) RunNow

func (s *Scheduler) RunNow(_ context.Context, name string) error

RunNow triggers the named job immediately in a new goroutine. Returns an error if no job with that name is registered. The job receives a detached context so it is not cancelled when the caller's context (e.g. an HTTP request) completes.

func (*Scheduler) Start

func (s *Scheduler) Start(ctx context.Context)

Start launches all jobs and blocks until ctx is cancelled. Each job runs in its own goroutine on its own ticker.

Directories

Path Synopsis
Package jobs provides the built-in scheduler job definitions.
Package jobs provides the built-in scheduler job definitions.

Jump to

Keyboard shortcuts

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