scheduler

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SHUTDOWN_TIMEOUT is the max time to wait for running jobs on shutdown.
	SHUTDOWN_TIMEOUT = 60 * time.Second
	// DEFAULT_JOB_TIMEOUT is the maximum duration a job will run without its own deadline.
	DEFAULT_JOB_TIMEOUT = time.Hour
)

TODO: Make this configurable via New options

Variables

This section is empty.

Functions

func ShouldRunLocalNow

func ShouldRunLocalNow(tzName string, hour int) bool

ShouldRunLocalNow returns true if the local time in tzName matches hour:minute exactly.

Types

type Job

type Job func(ctx context.Context)

Job is a unit of work to be run by the Scheduler.

type Scheduler

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

Scheduler runs Jobs on a fixed tick schedule. It also supports one-shot jobs and prevents concurrent runs of the same logical task (by ID). For each distinct id, only one instance may run at the same time.

func New

func New(tick time.Duration) (*Scheduler, error)

New creates a Scheduler that fires every tick duration.

func (*Scheduler) Add

func (s *Scheduler) Add(id string, slot int, job Job) error

Add registers a recurring job at the given slot (must be a multiple of granularity). id must be unique for each logical task; concurrent duplicates will be skipped.

func (*Scheduler) AddMany

func (s *Scheduler) AddMany(id string, slots []int, job Job) error

AddMany registers the same job on multiple slots. IDs must be distinct per logical task.

func (*Scheduler) RunOnce

func (s *Scheduler) RunOnce(ctx context.Context, id string, job Job) bool

RunOnce fires a one-shot job immediately. Returns true if the job was started, false if skipped because it's already running or invalid.

func (*Scheduler) Start

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

Start blocks until ctx is canceled. It aligns to the next tick boundary, then fires runJobs on each tick.

Jump to

Keyboard shortcuts

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