scheduler

package
v0.0.0-...-3bc99eb Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsOneShot

func IsOneShot(schedule string) bool

IsOneShot returns true if the schedule is a one-time reminder ("in ..." or "at ...").

Types

type Job

type Job struct {
	ID        int64
	Name      string
	Schedule  string // cron expression or "every Xm/Xh/Xd"
	SkillName string // skill to run, or empty for shell command
	Command   string // shell command if no skill
	Params    string // JSON params for skill
	Enabled   bool
	LastRun   *time.Time
	NextRun   time.Time
	FailCount int
	CreatedAt time.Time
}

Job represents a scheduled task.

type Scheduler

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

Scheduler manages cron-like scheduled jobs.

func New

func New(db *sql.DB, logger *slog.Logger) (*Scheduler, error)

New creates a scheduler backed by the given SQLite database.

func (*Scheduler) Count

func (s *Scheduler) Count() (int, error)

Count returns the total number of jobs.

func (*Scheduler) Create

func (s *Scheduler) Create(name, schedule, skillName, command, params string) (int64, error)

Create adds a new scheduled job.

func (*Scheduler) Delete

func (s *Scheduler) Delete(id int64) error

Delete removes a job.

func (*Scheduler) Get

func (s *Scheduler) Get(id int64) (*Job, error)

Get returns a job by ID.

func (*Scheduler) List

func (s *Scheduler) List(enabledOnly bool) ([]Job, error)

List returns all jobs, optionally filtered by enabled status.

func (*Scheduler) OnTrigger

func (s *Scheduler) OnTrigger(fn func(Job))

OnTrigger sets the callback invoked when a job fires.

func (*Scheduler) Pause

func (s *Scheduler) Pause(id int64) error

Pause disables a job.

func (*Scheduler) RecordFailure

func (s *Scheduler) RecordFailure(id int64) error

RecordFailure increments failure count and auto-pauses if threshold exceeded.

func (*Scheduler) RecordSuccess

func (s *Scheduler) RecordSuccess(id int64) error

RecordSuccess updates a job after successful execution.

func (*Scheduler) Resume

func (s *Scheduler) Resume(id int64) error

Resume enables a job and resets fail count.

func (*Scheduler) RunningCount

func (s *Scheduler) RunningCount() int

RunningCount returns the number of currently running jobs.

func (*Scheduler) SetMaxConcurrent

func (s *Scheduler) SetMaxConcurrent(n int)

SetMaxConcurrent sets the max number of concurrent cron jobs.

func (*Scheduler) Start

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

Start begins the scheduler tick loop.

func (*Scheduler) StopAll

func (s *Scheduler) StopAll()

StopAll cancels all running jobs.

Jump to

Keyboard shortcuts

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