Skip to content

Commit c413586

Browse files
committed
fix(scheduler): synchronize the started flag read
1 parent 4bb9433 commit c413586

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

quartz/scheduler.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ type Scheduler interface {
6868

6969
// StdScheduler implements the [Scheduler] interface.
7070
type StdScheduler struct {
71-
mtx sync.Mutex
71+
mtx sync.RWMutex
7272
wg sync.WaitGroup
7373

7474
interrupt chan struct{}
@@ -300,7 +300,7 @@ func (sched *StdScheduler) ScheduleJob(
300300

301301
if err = sched.queue.Push(toSchedule); err == nil {
302302
sched.logger.Debug("Successfully added job", "key", jobDetail.jobKey.String())
303-
if sched.started {
303+
if sched.IsStarted() {
304304
sched.Reset()
305305
}
306306
}
@@ -342,8 +342,8 @@ func (sched *StdScheduler) Wait(ctx context.Context) {
342342

343343
// IsStarted determines whether the scheduler has been started.
344344
func (sched *StdScheduler) IsStarted() bool {
345-
sched.mtx.Lock()
346-
defer sched.mtx.Unlock()
345+
sched.mtx.RLock()
346+
defer sched.mtx.RUnlock()
347347

348348
return sched.started
349349
}
@@ -391,7 +391,7 @@ func (sched *StdScheduler) DeleteJob(jobKey *JobKey) error {
391391
_, err := sched.queue.Remove(jobKey)
392392
if err == nil {
393393
sched.logger.Debug("Successfully deleted job", "key", jobKey.String())
394-
if sched.started {
394+
if sched.IsStarted() {
395395
sched.Reset()
396396
}
397397
}
@@ -426,7 +426,7 @@ func (sched *StdScheduler) PauseJob(jobKey *JobKey) error {
426426
}
427427
if err = sched.queue.Push(paused); err == nil {
428428
sched.logger.Debug("Successfully paused job", "key", jobKey.String())
429-
if sched.started {
429+
if sched.IsStarted() {
430430
sched.Reset()
431431
}
432432
}
@@ -466,7 +466,7 @@ func (sched *StdScheduler) ResumeJob(jobKey *JobKey) error {
466466
}
467467
if err = sched.queue.Push(resumed); err == nil {
468468
sched.logger.Debug("Successfully resumed job", "key", jobKey.String())
469-
if sched.started {
469+
if sched.IsStarted() {
470470
sched.Reset()
471471
}
472472
}
@@ -483,7 +483,7 @@ func (sched *StdScheduler) Clear() error {
483483
err := sched.queue.Clear()
484484
if err == nil {
485485
sched.logger.Debug("Successfully cleared job queue")
486-
if sched.started {
486+
if sched.IsStarted() {
487487
sched.Reset()
488488
}
489489
}

quartz/scheduler_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,12 @@ func TestScheduler(t *testing.T) {
105105
}
106106

107107
func TestScheduler_BlockingSemantics(t *testing.T) {
108+
t.Parallel()
109+
108110
for _, tt := range []string{"Blocking", "NonBlocking", "WorkerSmall", "WorkerLarge"} {
111+
tt := tt
109112
t.Run(tt, func(t *testing.T) {
113+
t.Parallel()
110114
var (
111115
workerLimit int
112116
opt quartz.SchedulerOpt

0 commit comments

Comments
 (0)