Documentation
¶
Overview ¶
Package schedule provides parsing and execution of schedule tokens.
Index ¶
- func ExtractScheduleTokens(text string, location *time.Location) ([]*Token, []ParseWarning)
- func IsImperativeLine(line string) bool
- func NextOccurrenceWithFilters(schedule *Token, filters []*Token, now time.Time, loc *time.Location) time.Time
- func TokenPattern() *regexp.Regexp
- type ActionHandler
- type Cron
- func (c *Cron) AddJob(job *Job)
- func (c *Cron) DisableJob(id string) bool
- func (c *Cron) EnableJob(id string) bool
- func (c *Cron) GetJob(id string) *Job
- func (c *Cron) GetJobs() []*Job
- func (c *Cron) GetJobsByPage(pageID string) []*Job
- func (c *Cron) IsRunning() bool
- func (c *Cron) JobCount() int
- func (c *Cron) RemoveJob(id string)
- func (c *Cron) RemoveJobsByPage(pageID string)
- func (c *Cron) SetErrorHandler(fn ErrorHandler)
- func (c *Cron) SetTimeFunc(fn func() time.Time)
- func (c *Cron) Start(ctx context.Context)
- func (c *Cron) Stop()
- func (c *Cron) Tick()
- func (c *Cron) UpdateJobToken(id string, token *Token) bool
- type ErrorHandler
- type Imperative
- type ImperativeType
- type Job
- type JobHandler
- type NotificationHandler
- type OffsetSpec
- type ParseWarning
- type Parser
- type RecurSpec
- type Runner
- func (r *Runner) AddJob(job *Job)
- func (r *Runner) GetAllJobs() []*Job
- func (r *Runner) GetImperatives(pageID string) []*Imperative
- func (r *Runner) GetJobsForPage(pageID string) []*Job
- func (r *Runner) GetWarnings() []ParseWarning
- func (r *Runner) ParsePage(pageID, content string) ([]*Imperative, error)
- func (r *Runner) RemovePage(pageID string)
- func (r *Runner) SetActionHandler(h ActionHandler)
- func (r *Runner) SetNotificationHandler(h NotificationHandler)
- func (r *Runner) SetTimeFunc(fn func() time.Time)
- func (r *Runner) Start(ctx context.Context) error
- func (r *Runner) Stop() error
- func (r *Runner) Tick()
- type RunnerConfig
- type TimeSpec
- type Token
- type TokenType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractScheduleTokens ¶
func ExtractScheduleTokens(text string, location *time.Location) ([]*Token, []ParseWarning)
ExtractScheduleTokens finds all schedule tokens in text (helper function).
func IsImperativeLine ¶
IsImperativeLine checks if a line is an imperative command.
func NextOccurrenceWithFilters ¶
func NextOccurrenceWithFilters(schedule *Token, filters []*Token, now time.Time, loc *time.Location) time.Time
NextOccurrenceWithFilters finds the next occurrence that passes all filter constraints. It iterates through schedule candidates until finding one that passes all filters.
func TokenPattern ¶
TokenPattern returns a regex pattern for matching schedule tokens.
Types ¶
type ActionHandler ¶
ActionHandler is called when an action should be executed. The message parameter contains any blockquote content associated with the imperative.
type Cron ¶
type Cron struct {
// contains filtered or unexported fields
}
Cron manages scheduled jobs and their execution timing.
func (*Cron) DisableJob ¶
DisableJob disables a job without removing it.
func (*Cron) GetJobsByPage ¶
GetJobsByPage returns all jobs for a specific page.
func (*Cron) RemoveJobsByPage ¶
RemoveJobsByPage removes all jobs for a specific page.
func (*Cron) SetErrorHandler ¶
func (c *Cron) SetErrorHandler(fn ErrorHandler)
SetErrorHandler sets a callback for job execution errors. If not set, errors are logged to stderr.
func (*Cron) SetTimeFunc ¶
SetTimeFunc sets a custom time function (for testing).
type ErrorHandler ¶
ErrorHandler is called when a job execution fails.
type Imperative ¶
type Imperative struct {
Type ImperativeType
Token *Token // The primary schedule token (e.g., @daily:9am)
FilterTokens []*Token // Filter tokens (e.g., @weekdays, @weekends)
Message string // For Notify: inline message, or blockquote content
ActionName string // For RunAction: the action name
Args []string // For RunAction: optional arguments
Line int // Source line number
Raw string // Original line text
}
Imperative represents a parsed imperative line.
func ExtractImperatives ¶
func ExtractImperatives(content string, location *time.Location) []*Imperative
ExtractImperatives returns all imperative lines from content.
func ParseImperativeLine ¶
func ParseImperativeLine(line string, location *time.Location) *Imperative
ParseImperativeLine parses a single imperative line (helper function).
type ImperativeType ¶
type ImperativeType int
ImperativeType indicates the type of imperative command.
const ( ImperativeNotify ImperativeType = iota ImperativeRunAction )
type Job ¶
type Job struct {
ID string
PageID string
Line string // The imperative line (e.g., "Notify @daily:9am Check email")
Token *Token
Filters []*Token // Filter tokens (e.g., @weekdays, @weekends) that constrain when job runs
NextRun time.Time
LastRun *time.Time
Enabled bool
Handler JobHandler
}
Job represents a scheduled job to be executed.
type JobHandler ¶
JobHandler is called when a job should execute.
type NotificationHandler ¶
NotificationHandler is called when a notification should be sent.
type OffsetSpec ¶
OffsetSpec represents a relative time offset.
type ParseWarning ¶
ParseWarning represents a non-fatal parsing issue.
type Parser ¶
type Parser struct {
Location *time.Location
Warnings []ParseWarning
}
Parser parses schedule tokens from text.
type RecurSpec ¶
type RecurSpec struct {
Days []time.Weekday // For weekly: specific days
DayOfMonth int // For monthly: day number (1-31)
Month time.Month // For yearly: month
Day int // For yearly: day of month
Time *TimeSpec // Time to trigger
}
RecurSpec represents a recurrence pattern.
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
Runner manages scheduled job execution.
func (*Runner) AddJob ¶
AddJob adds a pre-configured job to the scheduler. This is useful when jobs are created externally (e.g., from parsed Page imperatives).
func (*Runner) GetAllJobs ¶
GetAllJobs returns all scheduled jobs.
func (*Runner) GetImperatives ¶
func (r *Runner) GetImperatives(pageID string) []*Imperative
GetImperatives returns all imperatives for a page.
func (*Runner) GetJobsForPage ¶
GetJobsForPage returns all jobs for a specific page.
func (*Runner) GetWarnings ¶
func (r *Runner) GetWarnings() []ParseWarning
GetWarnings returns any parsing warnings.
func (*Runner) ParsePage ¶
func (r *Runner) ParsePage(pageID, content string) ([]*Imperative, error)
ParsePage extracts and registers imperative schedules from page content.
func (*Runner) RemovePage ¶
RemovePage removes all schedules for a page.
func (*Runner) SetActionHandler ¶
func (r *Runner) SetActionHandler(h ActionHandler)
SetActionHandler sets the callback for action execution.
func (*Runner) SetNotificationHandler ¶
func (r *Runner) SetNotificationHandler(h NotificationHandler)
SetNotificationHandler sets the callback for notifications.
func (*Runner) SetTimeFunc ¶
SetTimeFunc sets a custom time function (for testing).
type RunnerConfig ¶
type RunnerConfig struct {
Location *time.Location
StateDir string // Directory for state persistence (optional)
}
RunnerConfig configures a new Runner.
type Token ¶
type Token struct {
Raw string // Original token text (e.g., "@daily:9am")
Type TokenType // Type of schedule
Time *TimeSpec // Specific time (if applicable)
Recurring *RecurSpec // Recurrence pattern (if applicable)
Offset *OffsetSpec // Relative offset (if applicable)
Date *time.Time // Specific date (if applicable)
Line int // Source line number
Column int // Source column number
}
Token represents a parsed schedule token.
func (*Token) IsFilterToken ¶
IsFilterToken returns true if this token is a filter modifier (not a schedule).
func (*Token) NextOccurrence ¶
NextOccurrence calculates the next occurrence of this schedule token.
type TokenType ¶
type TokenType int
TokenType indicates the kind of schedule token.
const ( TokenRelative TokenType = iota // @today, @tomorrow, @yesterday TokenWeekday // @monday, @tuesday, etc. TokenISODate // @2024-03-15 TokenTime // @9am, @9:30pm TokenOffset // @in:2hours, @in:30min TokenDaily // @daily:9am TokenWeekly // @weekly:mon,wed TokenMonthly // @monthly:1st, @monthly:15 TokenYearly // @yearly:mar-15 TokenWeekdays // @weekdays - filter: Mon-Fri only TokenWeekends // @weekends - filter: Sat-Sun only )