Skip to content

Commit

Permalink
fix RunNow() when calling from a job returned by Jobs() (#668)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnRoesler authored Feb 2, 2024
1 parent 567cb96 commit b1ffc66
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
9 changes: 5 additions & 4 deletions scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,10 +454,11 @@ func (s *scheduler) now() time.Time {

func (s *scheduler) jobFromInternalJob(in internalJob) job {
return job{
id: in.id,
name: in.name,
tags: slices.Clone(in.tags),
jobOutRequest: s.jobOutRequestCh,
in.id,
in.name,
slices.Clone(in.tags),
s.jobOutRequestCh,
s.runJobRequestCh,
}
}

Expand Down
8 changes: 5 additions & 3 deletions scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1479,7 +1479,7 @@ func TestScheduler_RunJobNow(t *testing.T) {
{
"duration job - start immediately",
chDurationImmediate,
DurationJob(time.Second * 10),
DurationJob(time.Second * 5),
func() {
chDurationImmediate <- struct{}{}
},
Expand All @@ -1489,7 +1489,7 @@ func TestScheduler_RunJobNow(t *testing.T) {
),
},
func() time.Duration {
return 10 * time.Second
return 5 * time.Second
},
2,
},
Expand Down Expand Up @@ -1529,9 +1529,10 @@ func TestScheduler_RunJobNow(t *testing.T) {
t.Run(tt.name, func(t *testing.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)

j := s.Jobs()[0]
s.Start()

var nextRunBefore time.Time
Expand Down Expand Up @@ -1567,6 +1568,7 @@ func TestScheduler_RunJobNow(t *testing.T) {
nextRunAfter, err := j.NextRun()
if tt.expectedDiff != nil && tt.expectedDiff() > 0 {
for ; nextRunBefore.IsZero() || nextRunAfter.Equal(nextRunBefore); nextRunAfter, err = j.NextRun() { //nolint:revive
time.Sleep(100 * time.Millisecond)
}
}

Expand Down

0 comments on commit b1ffc66

Please sign in to comment.