fix RunNow() when calling from a job returned by Jobs() (#668)
This commit is contained in:
+5
-4
@@ -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
@@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user