Przeglądaj źródła

Make cron depend on interface instead of fixed parser

Yuri van Oers 6 lat temu
rodzic
commit
9c7462b344
2 zmienionych plików z 7 dodań i 2 usunięć
  1. 6 1
      cron.go
  2. 1 1
      option.go

+ 6 - 1
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()

+ 1 - 1
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
 	}