Documentation
¶
Index ¶
- func Reset(event Event)
- func ToToday(d time.Time) time.Time
- type Event
- type EventSys
- func (sys *EventSys) ClockEvent(h, m int, f func() error)
- func (sys *EventSys) EveryMinute(h, m, n int, f func() error)
- func (sys *EventSys) Register(event Event)
- func (sys *EventSys) Run(verbose bool)
- func (sys *EventSys) RunBackground(verbose bool)
- func (sys *EventSys) SimpleEvent(in time.Duration, once bool, f func() error)
- type SimpleEvent
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Event ¶
Event is an interface that will trigger at a specific hour and minute. Trigger() is the function that will be triggered. JustOnce() is if it should only be triggered once, or each day.
type EventSys ¶
type EventSys struct {
// contains filtered or unexported fields
}
EventSys represents an event system.
- granularity is how long it should wait at each loop in the main loop
- events is a map from Event to a margin of error on each side of the time when the event should kick in
- coolOffGranularity is how long the system should wait per cool-off loop iteration
func NewSystem ¶
NewSystem creates a new event system, where events can be registered and the event loop can be run. loopSleep is how long the event loop should sleep at every iteration.
func (*EventSys) ClockEvent ¶
ClockEvent creates and registers an event that should happen at every HH:MM
func (*EventSys) EveryMinute ¶
EveryMinute will trigger an event every minute for n minutes, starting from h:m
func (*EventSys) RunBackground ¶
RunBackground will start the event system in the background and immediately return
func (*EventSys) SimpleEvent ¶
SimpleEvent creates and registers an event that should happen in a certain amount of time from now, then may optionally be repeated at every matching hour and minute every 24 hours, if "once" is false.
type SimpleEvent ¶
type SimpleEvent struct {
// contains filtered or unexported fields
}
SimpleEvent is a simple event that will trigger a function at HH:MM
func NewClockEvent ¶
func NewClockEvent(h, m int, f func() error) *SimpleEvent
NewClockEvent will create a simple event that can be triggered The event will trigger every time the hour and minute matches the one from time.Now()
func NewSimpleEvent ¶
func NewSimpleEvent(in time.Duration, once bool, f func() error) *SimpleEvent
NewSimpleEvent will create a simple event that can be triggered
func NewTestEvent ¶
func NewTestEvent() *SimpleEvent
NewTestEvent will create a new event that will trigger in 5 seconds along with a log message
func (*SimpleEvent) Hour ¶
func (se *SimpleEvent) Hour() int
Hour will return the hour number for when the event should trigger
func (*SimpleEvent) JustOnce ¶
func (se *SimpleEvent) JustOnce() bool
JustOnce returns true if the event should only ever trigger once
func (*SimpleEvent) Minute ¶
func (se *SimpleEvent) Minute() int
Minute will return the minute number for when the event should trigger
func (*SimpleEvent) SetTriggerFunction ¶
func (se *SimpleEvent) SetTriggerFunction(f func() error)
SetTriggerFunction can be used for replacing the trigger function for a single event
func (*SimpleEvent) Trigger ¶
func (se *SimpleEvent) Trigger() error
Trigger will call the trigger function stored in the SimpleEvent struct