Skip to content

Commit

Permalink
add startedch to make sure scheduler is ready before client asks for …
Browse files Browse the repository at this point in the history
…info
  • Loading branch information
JohnRoesler committed Oct 30, 2023
1 parent b19fbe6 commit 293843f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 0 additions & 1 deletion example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,6 @@ func ExampleWithStartAt() {
defer func() {
_ = s.StopJobs()
}()
time.Sleep(10 * time.Millisecond)
next, _ := j.NextRun()
fmt.Println(next)
// Output:
Expand Down
4 changes: 4 additions & 0 deletions scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type scheduler struct {
globalJobOptions []JobOption

startCh chan struct{}
startedCh chan struct{}
stopCh chan struct{}
allJobsOutRequest chan allJobsOutRequest
jobOutRequestCh chan jobOutRequest
Expand Down Expand Up @@ -83,6 +84,7 @@ func NewScheduler(options ...SchedulerOption) (Scheduler, error) {
removeJobCh: make(chan uuid.UUID),
removeJobsByTagsCh: make(chan []string),
startCh: make(chan struct{}),
startedCh: make(chan struct{}),
stopCh: make(chan struct{}),
jobOutRequestCh: make(chan jobOutRequest),
allJobsOutRequest: make(chan allJobsOutRequest),
Expand Down Expand Up @@ -277,6 +279,7 @@ func (s *scheduler) selectStart() {
j.nextRun = next
s.jobs[id] = j
}
s.startedCh <- struct{}{}
}

// -----------------------------------------------
Expand Down Expand Up @@ -387,6 +390,7 @@ func (s *scheduler) RemoveJob(id uuid.UUID) error {
// on definition.
func (s *scheduler) Start() {
s.startCh <- struct{}{}
<-s.startedCh
}

// StopJobs stops the execution of all jobs in the scheduler.
Expand Down

0 comments on commit 293843f

Please sign in to comment.