scheduler

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseCronNext added in v0.10.0

func ParseCronNext(cronExpr string, from time.Time) (time.Time, error)

ParseCronNext parses a cron expression and returns the next scheduled time Supports 6-field cron syntax (with seconds) and descriptors like @weekly, @daily, etc. Format: second minute hour day month weekday

@weekly	= Monday 00:00:00 UTC

Types

type CronScheduler

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

CronScheduler implements Scheduler using robfig/cron

func NewCronScheduler

func NewCronScheduler(logger *zap.SugaredLogger) *CronScheduler

NewCronScheduler creates a new cron-based scheduler

func (*CronScheduler) ListJobs

func (s *CronScheduler) ListJobs() []string

ListJobs returns all registered job names

func (*CronScheduler) RunNow

func (s *CronScheduler) RunNow(ctx context.Context, jobName string) error

RunNow executes a job immediately by name

func (*CronScheduler) Schedule

func (s *CronScheduler) Schedule(schedule Schedule, job Job) error

Schedule adds a job to run on the given schedule

func (*CronScheduler) ScheduleCron

func (s *CronScheduler) ScheduleCron(cronExpr string, job Job) error

ScheduleCron adds a job with a custom cron expression Cron format: second minute hour day month weekday (6 fields with seconds support) Examples:

"0 0 * * * *"     - Every hour at minute 0
"0 */5 * * * *"   - Every 5 minutes
"0 0 0 * * *"     - Every day at midnight
"@hourly"         - Every hour (equivalent to "0 0 * * * *")

func (*CronScheduler) Start

func (s *CronScheduler) Start()

Start begins processing scheduled jobs

func (*CronScheduler) Stop

func (s *CronScheduler) Stop() context.Context

Stop gracefully stops the scheduler

type Job

type Job interface {
	// Name returns the unique name of the job
	Name() string
	// Execute runs the job
	Execute(ctx context.Context) error
}

Job represents a scheduled job that can be executed

type Schedule

type Schedule string

Schedule represents when a job should run

const (
	// ScheduleDaily runs the job once per day at midnight UTC
	ScheduleDaily Schedule = "@daily"
	// ScheduleWeekly runs the job once per week on Sunday at midnight UTC
	ScheduleWeekly Schedule = "@weekly"
	// ScheduleMonthly runs the job once per month on the 1st at midnight UTC
	ScheduleMonthly Schedule = "@monthly"
)

type Scheduler

type Scheduler interface {
	// Schedule adds a job to run on the given schedule
	Schedule(schedule Schedule, job Job) error
	// ScheduleCron adds a job with a custom cron expression
	ScheduleCron(cronExpr string, job Job) error
	// Start begins processing scheduled jobs
	Start()
	// Stop gracefully stops the scheduler
	Stop() context.Context
	// RunNow executes a job immediately by name (useful for testing/manual triggers)
	RunNow(ctx context.Context, jobName string) error
	// ListJobs returns all registered job names
	ListJobs() []string
}

Scheduler is the interface for scheduling and managing jobs This abstraction allows swapping the underlying scheduler implementation (e.g., from built-in cron to an external scheduler like Temporal or a message queue)

Jump to

Keyboard shortcuts

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