Created
April 16, 2018 22:11
-
-
Save whatsadebugger/18ba4b803ed1da5ce466a9ff70a6c268 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// RunJobAt wait until the Stop() function has been called on the run | |
// or the specified time for the run is after the present time. | |
func (ot *OneTime) RunJobAt(initr models.Initiator, job models.JobSpec) { | |
select { | |
case <-ot.done: | |
case <-ot.Clock.After(initr.Time.DurationFromNow()): | |
if initr.Ran { | |
logger.Error((fmt.Errorf("Job runner: Initiator: %v cannot be run more than once", initr.ID))) | |
return | |
} | |
initr.Ran = true | |
_, err := BeginRun(job, initr, models.RunResult{}, ot.Store) | |
if err != nil { | |
logger.Error(err.Error()) | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func TestOneTime_RunJobAt_RunTwice(t *testing.T) { | |
t.Parallel() | |
store, cleanup := cltest.NewStore() | |
defer cleanup() | |
ot := services.OneTime{ | |
Clock: store.Clock, | |
Store: store, | |
} | |
j, initr := cltest.NewJobWithRunAtInitiator(time.Now()) | |
assert.Nil(t, store.SaveJob(&j)) | |
ot.RunJobAt(initr, j) | |
initr.Time = models.Time{Time: time.Now().Add(time.Second * 2)} | |
ot.RunJobAt(initr, j) | |
jobRuns := []models.JobRun{} | |
assert.Nil(t, store.Where("JobID", j.ID, &jobRuns)) | |
assert.Equal(t, 1, len(jobRuns)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment