cmd/jobrun: repeat strategies as part of jobrun

This commit is contained in:
Christian Schwarz
2017-06-09 21:00:28 +02:00
parent 93d098162e
commit af2aa9dfe1
5 changed files with 96 additions and 23 deletions
+25
View File
@@ -0,0 +1,25 @@
package jobrun
import (
"time"
)
type NoRepeatStrategy struct{}
func (s NoRepeatStrategy) ShouldReschedule(lastResult JobRunResult) (time.Time, bool) {
return time.Time{}, false
}
type PeriodicRepeatStrategy struct {
Interval time.Duration
}
func (s *PeriodicRepeatStrategy) ShouldReschedule(lastResult JobRunResult) (next time.Time, shouldRun bool) {
// Don't care about the result
shouldRun = true
next = lastResult.Start.Add(s.Interval)
if next.Before(time.Now()) {
next = time.Now()
}
return
}