Documentation
¶
Index ¶
- Constants
- func BuildMissedNotification(tasks []Job) string
- func HumanSchedule(schedule string) string
- func JitteredNextFire(expr *CronExpr, after time.Time, id string) (time.Time, bool)
- func NextMatch(expr *CronExpr, after time.Time) (time.Time, bool)
- func OneShotJitteredFireTime(expr *CronExpr, createdAt time.Time, id string) (time.Time, bool)
- func ProcessAlive(pid int) bool
- type CronExpr
- type Job
- type Scheduler
- type SchedulerConfig
- type Store
- func (s *Store) AcquireLock(sessionID string) bool
- func (s *Store) ConfigDir() string
- func (s *Store) Create(schedule, prompt string, recurring, durable bool) (*Job, error)
- func (s *Store) Delete(id string) error
- func (s *Store) DeleteAll() int
- func (s *Store) DeleteDurableByIDs(ids []string)
- func (s *Store) DurableFilePath() string
- func (s *Store) Get(id string) (Job, bool)
- func (s *Store) Len() int
- func (s *Store) List() []Job
- func (s *Store) LoadDurableJobs() error
- func (s *Store) LockFilePath() string
- func (s *Store) MissedDurableJobs() []Job
- func (s *Store) ReleaseLock(sessionID string)
- func (s *Store) SetConfigDir(dir string)
- func (s *Store) StartWriter()
- func (s *Store) StopWriter()
- func (s *Store) TickDurableJobs(now time.Time) []string
- func (s *Store) TickSessionJobs(now time.Time) []string
Constants ¶
const ( MaxJobs = 50 RecurringMaxAge = 3 * 24 * time.Hour )
Variables ¶
This section is empty.
Functions ¶
func BuildMissedNotification ¶
BuildMissedNotification creates a prompt text asking the user about missed tasks.
func HumanSchedule ¶
HumanSchedule returns a human-readable description of a schedule string.
func JitteredNextFire ¶
JitteredNextFire computes the next fire time with jitter for a recurring cron job.
func NextMatch ¶
NextMatch finds the next time after 'after' that matches the cron expression. Implements standard cron DOM/DOW union logic: when both are restricted, a day matches if EITHER condition is true (OR semantics).
func OneShotJitteredFireTime ¶
OneShotJitteredFireTime computes the fire time for a one-shot cron job. If the fire minute lands on :00 or :30, it shifts up to 90s early to avoid thundering herd.
func ProcessAlive ¶ added in v0.3.0
ProcessAlive reports whether a process with the given PID exists. Exported for reuse outside the scheduler (e.g. dream's consolidation lock).
Types ¶
type CronExpr ¶
CronExpr holds parsed 5-field cron expression values.
type Job ¶
type Job struct {
ID string `json:"id"`
Schedule string `json:"schedule"`
Prompt string `json:"prompt"`
Recurring bool `json:"recurring,omitempty"`
CreatedAt int64 `json:"createdAt"` // Unix milliseconds
Durable bool `json:"durable,omitempty"`
// contains filtered or unexported fields
}
Job is a scheduled task.
func (*Job) CreatedTime ¶
CreatedTime returns CreatedAt as time.Time.
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler ticks every second and fires ready jobs from both tracks.
func NewScheduler ¶
func NewScheduler(cfg SchedulerConfig) *Scheduler
NewScheduler creates a scheduler (not yet started).
type SchedulerConfig ¶
type SchedulerConfig struct {
Store *Store
SessionID string // for lock ownership
RestoreDurable bool // load durable jobs from disk (only for resumed sessions)
OnFire func(prompt string)
IsBusy func() bool
}
SchedulerConfig configures the scheduler.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store manages both session and durable cron jobs.
func NewStore ¶
func NewStore() *Store
NewStore creates an empty Store. Call SetConfigDir to enable durable storage.
func (*Store) AcquireLock ¶
AcquireLock tries to acquire the scheduler lock. Returns true if acquired.
func (*Store) DeleteDurableByIDs ¶
DeleteDurableByIDs removes durable jobs by ID and persists. Used by scheduler for cleanup.
func (*Store) DurableFilePath ¶
DurableFilePath returns the tasks file path.
func (*Store) List ¶
List returns a snapshot of all jobs (session + durable) sorted by creation time.
func (*Store) LoadDurableJobs ¶
LoadDurableJobs reads scheduled_tasks.json from the session directory and loads valid jobs.
func (*Store) LockFilePath ¶
LockFilePath returns the lock file path for the scheduler.
func (*Store) MissedDurableJobs ¶
MissedDurableJobs returns durable one-shot jobs whose first fire time is in the past.
func (*Store) ReleaseLock ¶
ReleaseLock releases the scheduler lock if we own it.
func (*Store) SetConfigDir ¶
SetConfigDir enables durable storage (e.g. ~/.codebot/projects/<projectID>/<sessionID>).
func (*Store) StartWriter ¶
func (s *Store) StartWriter()
StartWriter launches the background goroutine that writes durable jobs to disk.
func (*Store) StopWriter ¶
func (s *Store) StopWriter()
StopWriter stops the writer goroutine and waits for the final flush.
func (*Store) TickDurableJobs ¶
TickDurableJobs fires ready durable jobs. Returns prompts and persists changes.