schedule

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Job

type Job struct {
	Interval time.Duration
	CronExpr string
	Task     Task
}

Job represents a registered task with its scheduling constraints.

type Scheduler

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

Scheduler manages the execution of periodic background jobs.

func New

func New() *Scheduler

New creates a new task scheduler.

func (*Scheduler) Cron

func (s *Scheduler) Cron(expr string, task Task) *Job

Cron registers a task to run repeatedly according to a 5-field cron expression.

func (*Scheduler) Every

func (s *Scheduler) Every(interval time.Duration, task Task) *Job

Every registers a task to run repeatedly at the given interval.

func (*Scheduler) Run

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

Run starts the scheduler in the background. It blocks until the context is canceled. Typically, you call this in a goroutine: `go scheduler.Run(ctx)`

func (*Scheduler) Stop

func (s *Scheduler) Stop()

Stop sends the cancellation signal to all jobs and waits for them to finish.

type Task

type Task func() error

Task represents a function that can be scheduled.

Jump to

Keyboard shortcuts

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