cron

package
v1.1.64 Latest Latest
Warning

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

Go to latest
Published: May 1, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NextTime

func NextTime(expr string, from time.Time) (time.Time, error)

NextTime calculates the next time that matches the 5-field cron expression after the given 'from' time. Returns the next fire time or an error.

Supported syntax per field:

  • * — any value
  • */N — every Nth value
  • N — exact value
  • N,M,K — list of values
  • N-M — range (inclusive)
  • N-M/S — range with step

Types

type Job

type Job struct {
	ID        string
	CronExpr  string
	Prompt    string
	Recurring bool
	CreatedAt time.Time
	NextFire  time.Time
}

Job represents a scheduled prompt job.

func (*Job) Snapshot

func (j *Job) Snapshot() Job

Snapshot returns a copy of the job safe for external use.

type Scheduler

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

Scheduler manages in-memory cron-like prompt scheduling.

func NewScheduler

func NewScheduler(enqueue func(prompt string)) *Scheduler

NewScheduler creates a scheduler with the given enqueue callback. The enqueue callback is called when a job fires, typically injecting the prompt into the TUI's conversation.

func (*Scheduler) Create

func (s *Scheduler) Create(cronExpr, prompt string, recurring bool) (Job, error)

Create adds a new scheduled job and returns its snapshot. The cron expression is a standard 5-field format:

minute hour day-of-month month day-of-week

Supports: *, */N, N, N-M, N,M,K, N-M/S

func (*Scheduler) Delete

func (s *Scheduler) Delete(id string) bool

Delete removes a scheduled job by ID.

func (*Scheduler) Get

func (s *Scheduler) Get(id string) (Job, bool)

Get retrieves a job by ID.

func (*Scheduler) List

func (s *Scheduler) List() []Job

List returns snapshots of all jobs.

func (*Scheduler) SetEnqueue

func (s *Scheduler) SetEnqueue(fn func(prompt string))

SetEnqueue sets or replaces the enqueue callback. Use this when the scheduler is created before the TUI is available.

func (*Scheduler) Shutdown

func (s *Scheduler) Shutdown()

Shutdown stops all timers and clears all jobs. The scheduler cannot be reused after shutdown.

Jump to

Keyboard shortcuts

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