# README
Package github.com/cosnicolaou/automation/scheduler
import github.com/cosnicolaou/automation/scheduler
Variables
AnnualDynamic, DailyDynamic
AnnualDynamic = map[string]datetime.DynamicDateRange{
"summer": astronomy.Summer{},
"winter": astronomy.Winter{},
"spring": astronomy.Spring{},
"fall": astronomy.Autumn{LocalName: "Fall"},
"autumn": astronomy.Autumn{},
"winter-solstice": astronomy.WinterSolstice{},
"summer-solstice": astronomy.SummerSolstice{},
"spring-equinox": astronomy.SpringEquinox{},
"fall-equinox": astronomy.AutumnEquinox{},
"autumn-equinox": astronomy.AutumnEquinox{},
}
DailyDynamic = map[string]datetime.DynamicTimeOfDay{
"sunrise": astronomy.SunRise{},
"sunset": astronomy.SunSet{},
"solarnoon": astronomy.SolarNoon{},
}
ErrOpTimeout
ErrOpTimeout = errors.New("op-timeout")
Functions
Func ParseActionTime
func ParseActionTime(v string) (datetime.TimeOfDay, datetime.DynamicTimeOfDay, time.Duration, error)
ParseAction parses a time of day that may contain a dynamic time of day function with a +- delta. Valid dynamic time of day functions are defined by DailyDynamic.
Func ParseDateRangesDynamic
func ParseDateRangesDynamic(vals []string) (datetime.DateRangeList, datetime.DynamicDateRangeList, error)
ParseDateRangesDynamic parses a list of date ranges that may contain dynamic date ranges. Valid dynamic date ranges are definmed by AnnualDynamic.
Func RunSchedulers
func RunSchedulers(ctx context.Context, schedules Schedules, system devices.System, start datetime.CalendarDate, opts ...Option) error
RunSchedulers runs the supplied schedules against the supplied system starting at the specified date until the context is canceled. Note that the WithTimeSource option should not be used with this function as it will be used by all of the schedulers created which is likely not what is intended. Note that the Simulate function can be used to run multiple schedules using simulated time appropriate for each schedule.
Func RunSimulation
func RunSimulation(ctx context.Context, schedules Schedules, system devices.System, period datetime.CalendarDateRange, opts ...Option) error
RunSimulation runs the specified schedules against the specified system for the specified period using a similated time.
Types
Type Action
type Action struct {
devices.Action
Precondition Precondition
}
Action represents a single action to be taken on any given day.
Type ActionTime
type ActionTime struct {
Literal datetime.TimeOfDay
Dynamic datetime.DynamicTimeOfDay
Delta time.Duration
}
ActionTime represents a time of day that may be a literal or a dynamic value.
Type ActionTimeList
type ActionTimeList []ActionTime
Methods
func (atl *ActionTimeList) Parse(val string) error
Type Annual
type Annual struct {
Name string
Dates schedule.Dates
DailyActions schedule.ActionSpecs[Action]
}
Type Calendar
type Calendar struct {
// contains filtered or unexported fields
}
Functions
func NewCalendar(schedules Schedules, system devices.System, opts ...Option) (*Calendar, error)
Methods
func (c *Calendar) Scheduled(date datetime.CalendarDate) []CalendarEntry
Type CalendarEntry
type CalendarEntry struct {
Schedule string
schedule.Active[Action]
}
Type Option
type Option func(o *options)
Functions
func WithDryRun(v bool) Option
func WithLogger(l *slog.Logger) Option
WithLogger sets the logger to be used by the scheduler and is also passed to all device operations/conditions.
func WithOperationWriter(w io.Writer) Option
WithOperationWriter sets the output writer that operations can use for interactive output.
func WithSimulationDelay(d time.Duration) Option
func WithStatusRecorder(sr *logging.StatusRecorder) Option
func WithTimeSource(ts TimeSource) Option
WithTimeSource sets the time source to be used by the scheduler and is primarily intended for testing purposes.
Type Precondition
type Precondition struct {
Device string
Name string
Condition devices.Condition
Args []string
}
Type Scheduler
type Scheduler struct {
// contains filtered or unexported fields
}
Functions
func New(sched Annual, system devices.System, opts ...Option) (*Scheduler, error)
New creates a new scheduler for the supplied schedule and associated devices.
Methods
func (s *Scheduler) Place() datetime.Place
func (s *Scheduler) RunDay(ctx context.Context, place datetime.Place, active schedule.Scheduled[Action]) error
func (s *Scheduler) RunYear(ctx context.Context, cd datetime.CalendarDate) error
Run runs the scheduler from the specified calendar date to the last of the scheduled actions for that year.
func (s *Scheduler) RunYearEnd(ctx context.Context, cd datetime.CalendarDate) error
RunYear runs the scheduler from the specified calendar date to the end of that year.
func (s *Scheduler) ScheduledYearEnd(cd datetime.CalendarDate) iter.Seq[schedule.Scheduled[Action]]
Type Schedules
type Schedules struct {
System devices.System
Schedules []Annual
}
Functions
func ParseConfig(_ context.Context, cfgData []byte, system devices.System) (Schedules, error)
func ParseConfigFile(ctx context.Context, cfgFile string, system devices.System) (Schedules, error)
Methods
func (s Schedules) Lookup(name string) Annual
Type SystemTimeSource
type SystemTimeSource struct{}
Methods
func (SystemTimeSource) NowIn(loc *time.Location) time.Time
Type TimeSource
type TimeSource interface {
NowIn(in *time.Location) time.Time
}
TimeSource is an interface that provides the current time in a specific location and is intended for testing purposes. It will be called once per iteration of the scheduler to schedule the next action. time.Now().In() will be used for all other time operations.
TODO
- cnicolaou: implement retries.