fix RunNow() when calling from a job returned by Jobs() (#668)

This commit is contained in:
John Roesler
2024-02-02 09:46:08 -06:00
committed by GitHub
parent 567cb9695c
commit b1ffc665fb
2 changed files with 10 additions and 7 deletions
+5 -4
View File
@@ -454,10 +454,11 @@ func (s *scheduler) now() time.Time {
func (s *scheduler) jobFromInternalJob(in internalJob) job { func (s *scheduler) jobFromInternalJob(in internalJob) job {
return job{ return job{
id: in.id, in.id,
name: in.name, in.name,
tags: slices.Clone(in.tags), slices.Clone(in.tags),
jobOutRequest: s.jobOutRequestCh, s.jobOutRequestCh,
s.runJobRequestCh,
} }
} }
+5 -3
View File
@@ -1479,7 +1479,7 @@ func TestScheduler_RunJobNow(t *testing.T) {
{ {
"duration job - start immediately", "duration job - start immediately",
chDurationImmediate, chDurationImmediate,
DurationJob(time.Second * 10), DurationJob(time.Second * 5),
func() { func() {
chDurationImmediate <- struct{}{} chDurationImmediate <- struct{}{}
}, },
@@ -1489,7 +1489,7 @@ func TestScheduler_RunJobNow(t *testing.T) {
), ),
}, },
func() time.Duration { func() time.Duration {
return 10 * time.Second return 5 * time.Second
}, },
2, 2,
}, },
@@ -1529,9 +1529,10 @@ func TestScheduler_RunJobNow(t *testing.T) {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
s := newTestScheduler(t) s := newTestScheduler(t)
j, err := s.NewJob(tt.j, NewTask(tt.fun), tt.opts...) _, err := s.NewJob(tt.j, NewTask(tt.fun), tt.opts...)
require.NoError(t, err) require.NoError(t, err)
j := s.Jobs()[0]
s.Start() s.Start()
var nextRunBefore time.Time var nextRunBefore time.Time
@@ -1567,6 +1568,7 @@ func TestScheduler_RunJobNow(t *testing.T) {
nextRunAfter, err := j.NextRun() nextRunAfter, err := j.NextRun()
if tt.expectedDiff != nil && tt.expectedDiff() > 0 { if tt.expectedDiff != nil && tt.expectedDiff() > 0 {
for ; nextRunBefore.IsZero() || nextRunAfter.Equal(nextRunBefore); nextRunAfter, err = j.NextRun() { //nolint:revive for ; nextRunBefore.IsZero() || nextRunAfter.Equal(nextRunBefore); nextRunAfter, err = j.NextRun() { //nolint:revive
time.Sleep(100 * time.Millisecond)
} }
} }