From 9c7462b344a041c8b85b8110f0832d745c221c4f Mon Sep 17 00:00:00 2001 From: Yuri van Oers Date: Wed, 9 Oct 2019 23:28:31 +0200 Subject: [PATCH] Make cron depend on interface instead of fixed parser --- cron.go | 7 ++++++- option.go | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cron.go b/cron.go index f6e451db..c7e91766 100644 --- a/cron.go +++ b/cron.go @@ -21,11 +21,16 @@ type Cron struct { logger Logger runningMu sync.Mutex location *time.Location - parser Parser + parser ScheduleParser nextID EntryID jobWaiter sync.WaitGroup } +// ScheduleParser is an interface for schedule spec parsers that return a Schedule +type ScheduleParser interface { + Parse(spec string) (Schedule, error) +} + // Job is an interface for submitted cron jobs. type Job interface { Run() diff --git a/option.go b/option.go index 07638201..09e4278e 100644 --- a/option.go +++ b/option.go @@ -23,7 +23,7 @@ func WithSeconds() Option { } // WithParser overrides the parser used for interpreting job schedules. -func WithParser(p Parser) Option { +func WithParser(p ScheduleParser) Option { return func(c *Cron) { c.parser = p }