scheduler

package
v0.0.75 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package scheduler implements a cron-based scheduler that fires registered schedules (see internal/schedule) and creates Tasks at their scheduled times.

The scheduler runs as a singleton goroutine started from cmd/taskguild-server/run.go. It uses github.com/robfig/cron/v3 as the underlying cron runner with the standard 5-field parser and the server's local timezone. Missed firings during downtime are skipped (no catch-up).

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 manages the cron entries for all enabled schedules and dispatches task creation when entries fire.

func New

New creates a Scheduler. Start must be called to begin firing entries.

func (*Scheduler) Add

func (s *Scheduler) Add(sched *schedule.Schedule) error

Add registers a schedule. If the schedule is already registered, the previous entry is removed first.

func (*Scheduler) NextRun

func (s *Scheduler) NextRun(expr string, from time.Time) time.Time

NextRun computes the next firing time of expr (5-field cron) after from. Returns the zero Time if the expression is invalid.

func (*Scheduler) Remove

func (s *Scheduler) Remove(id string)

Remove unregisters a schedule. No-op if it was not registered.

func (*Scheduler) SetLocation

func (s *Scheduler) SetLocation(loc *time.Location)

SetLocation overrides the cron timezone (default: time.Local). Must be called before Start.

func (*Scheduler) Start

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

Start initializes the cron runner, registers every enabled schedule from the repository, and runs until ctx is canceled. Safe to call once per Scheduler.

func (*Scheduler) Update

func (s *Scheduler) Update(sched *schedule.Schedule) error

Update re-registers a schedule with new parameters. Equivalent to Add but communicates intent.

type TaskCreator

type TaskCreator interface {
	CreateTaskFromSchedule(ctx context.Context, s *schedule.Schedule, firedAt time.Time) (*task.Task, error)
}

TaskCreator abstracts the cross-package call into internal/task so the scheduler can be tested without spinning up a full task.Server.

type TaskCreatorAdapter

type TaskCreatorAdapter struct {
	TaskServer *task.Server
}

TaskCreatorAdapter bridges scheduler.TaskCreator to task.Server. It expands title/description placeholders and attaches schedule provenance metadata.

func NewTaskCreatorAdapter

func NewTaskCreatorAdapter(ts *task.Server) *TaskCreatorAdapter

NewTaskCreatorAdapter constructs an adapter wired to the provided task server.

func (*TaskCreatorAdapter) CreateTaskFromSchedule

func (a *TaskCreatorAdapter) CreateTaskFromSchedule(ctx context.Context, s *schedule.Schedule, firedAt time.Time) (*task.Task, error)

Jump to

Keyboard shortcuts

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