Skip to content

Commit

Permalink
Don't require an interval with a repeat of zero
Browse files Browse the repository at this point in the history
  • Loading branch information
AJ Bahnken committed May 8, 2016
1 parent 87ff31b commit 82caaa9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
12 changes: 7 additions & 5 deletions job/job.go
Expand Up @@ -220,12 +220,14 @@ func (j *Job) InitDelayDuration(checkTime bool) error {
}
log.Debugf("Schedule Time: %s", j.scheduleTime)

j.delayDuration, err = iso8601.FromString(splitTime[2])
if err != nil {
log.Errorf("Error converting delayDuration to a iso8601.Duration: %s", err)
return err
if j.timesToRepeat != 0 {
j.delayDuration, err = iso8601.FromString(splitTime[2])
if err != nil {
log.Errorf("Error converting delayDuration to a iso8601.Duration: %s", err)
return err
}
log.Debugf("Delay Duration: %s", j.delayDuration.ToDuration())
}
log.Debugf("Delay Duration: %s", j.delayDuration.ToDuration())

if j.Epsilon != "" {
j.epsilonDuration, err = iso8601.FromString(j.Epsilon)
Expand Down
18 changes: 18 additions & 0 deletions job/job_test.go
@@ -1,6 +1,7 @@
package job

import (
"fmt"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -165,6 +166,23 @@ func TestJobRun(t *testing.T) {
assert.WithinDuration(t, j.Metadata.LastAttemptedRun, now, 2*time.Second)
}

func TestJobWithRepeatOfZeroAndNoInterval(t *testing.T) {
cache := NewMockCache()

j := GetMockJob()
parsedTime := time.Now().Add(time.Minute * 5).Format(time.RFC3339)
scheduleStr := fmt.Sprintf("R%d/%s/", 0, parsedTime)
j.Schedule = scheduleStr
j.Init(cache)
j.Run(cache)

now := time.Now()

assert.Equal(t, j.Metadata.SuccessCount, uint(1))
assert.WithinDuration(t, j.Metadata.LastSuccess, now, 2*time.Second)
assert.WithinDuration(t, j.Metadata.LastAttemptedRun, now, 2*time.Second)
}

func TestJobRunAndRepeat(t *testing.T) {
cache := NewMockCache()

Expand Down

0 comments on commit 82caaa9

Please sign in to comment.