Documentation ¶
Overview ¶
Package timer produces events that start scheduler jobs on pre-defined dates and/or intervals.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EventProducer ¶
type EventProducer struct { Context context.Context Waiters map[string]*ScheduleWaiter EventChan chan *jobs.JobTriggerEvent StopChan chan bool }
EventProducer gathers all ScheduleWaiters in a pool and provides a single entry point to communicate with them, typically to stop them.
func NewEventProducer ¶
func NewEventProducer(rootCtx context.Context) *EventProducer
NewEventProducer creates a pool of ScheduleWaiters that will send events based on pre-defined scheduling.
func (*EventProducer) Start ¶
func (e *EventProducer) Start() error
Start loads all TimersOnly Jobs from the job repository and registers them in this EventProducer pool.
func (*EventProducer) StartOrUpdateJob ¶
func (e *EventProducer) StartOrUpdateJob(job *jobs.Job)
StartOrUpdateJob creates a ScheduleWaiter and registers it in the EventProducer pool. If a waiter already exists for the same job ID it will be stopped and replaced with a new one.
func (*EventProducer) StopAll ¶
func (e *EventProducer) StopAll()
StopAll ranges all waiters from the EventProducer, calls Stop() and remove them from the Waiter pool.
func (*EventProducer) StopWaiter ¶
func (e *EventProducer) StopWaiter(jobId string)
StopWaiter stops a waiter given its ID and remove it from the Waiter pool. If no waiter with this ID is registered, it returns silently.
type JobsEventsSubscriber ¶
type JobsEventsSubscriber struct {
Producer *EventProducer
}
JobsEventsSubscriber provides an entry point to add, update or remove Scheduler Jobs.
func (*JobsEventsSubscriber) Handle ¶
func (e *JobsEventsSubscriber) Handle(ctx context.Context, msg *jobs.JobChangeEvent) error
Handle passes JobChangeEvents to the registered event producer.
type ScheduleWaiter ¶
ScheduleWaiter provides an easy way to execute a job at given times (like a cron job).
func NewScheduleWaiter ¶
func NewScheduleWaiter(jobId string, schedule *jobs.Schedule, tickerChannel chan *jobs.JobTriggerEvent) *ScheduleWaiter
NewScheduleWaiter creates a new waiter that sends start events for this job on the given schedule
func (*ScheduleWaiter) ParseSchedule ¶
func (w *ScheduleWaiter) ParseSchedule() error
ParseSchedule parses the given Iso 8601 string and stores corresponding values in the waiter to ease processing.
func (*ScheduleWaiter) WaitUntilNext ¶
func (w *ScheduleWaiter) WaitUntilNext()
WaitUntilNext implements the intelligence of the waiter.