cron

package
v1.3.101 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MigrateWorkspaceJobs added in v1.3.100

func MigrateWorkspaceJobs(oldStorePath, newSessionPath, workspaceDir string)

MigrateWorkspaceJobs moves recurring jobs from the old workspace-scoped store file to the new per-session store file. It removes the migrated workspace bucket from the old file, ensuring each workspace's jobs are migrated exactly once (by the first instance that starts).

If oldStorePath doesn't exist, the workspace has no bucket, or the new store already exists, migration is a no-op.

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
	QueueIfBusy bool // if true, queue the prompt when agent is busy; if false (default), skip
	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 cron-like prompt scheduling with optional persistence.

func NewScheduler

func NewScheduler(enqueue func(prompt string, queueIfBusy bool), storePath string) *Scheduler

NewScheduler creates a scheduler with the given enqueue callback and optional persistence path. If storePath is empty, no persistence is used (useful for tests).

func (*Scheduler) Create

func (s *Scheduler) Create(cronExpr, prompt string, recurring bool, queueIfBusy 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) DeleteWithError added in v1.3.68

func (s *Scheduler) DeleteWithError(id string) (bool, error)

DeleteWithError removes a scheduled job by ID and reports persistence errors.

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) Load added in v1.3.68

func (s *Scheduler) Load()

Load reads persisted recurring jobs for this session and schedules them. Must be called after NewScheduler, before any Create/Delete calls. If storePath is empty or the file doesn't exist, Load is a no-op.

func (*Scheduler) SetEnqueue

func (s *Scheduler) SetEnqueue(fn func(prompt string, queueIfBusy bool))

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

func (*Scheduler) SetSession added in v1.3.100

func (s *Scheduler) SetSession(storePath, oldStorePath, workspaceDir string)

SetSession binds this scheduler to a session store path, migrating from the old workspace-scoped store if needed, then loading. This is used when the session ID is not yet known at scheduler creation time (e.g., TUI new session or desktop lazy init).

storePath is the per-session JSON file path. oldStorePath is the legacy cron-jobs.json path (empty to skip migration). workspaceDir is the working directory key for migration (empty to skip).

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