Skip to content

Commit

Permalink
fix race-condition in scheduler thread
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Langenhahn committed Jul 24, 2020
1 parent ea27cbe commit a7e5866
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@ class JesqueSchedulerService {
if (!waitingJobs)
return []

//only get and wait for jobs with the exact time until something like quartz batchTimeWindow is implemented
def earliestWaitingJobTime = waitingJobs.min { it.score }.score
waitingJobs.findAll { it.score == earliestWaitingJobTime }

//lock jobs
waitingJobs.inject([]) { List<Tuple> acquiredJobs, Tuple jobData ->
String jobName = jobData.element
Expand All @@ -120,6 +116,12 @@ class JesqueSchedulerService {
return acquiredJobs
}

if (jobData.score != trigger.nextFireTime.millis) {
log.debug "Trigger nextFireTime has been changed: job $jobName was already executed by another thread"
redis.unwatch()
return acquiredJobs
}

trigger.state = TriggerState.Acquired
trigger.acquiredBy = hostName
Transaction transaction = redis.multi()
Expand Down

0 comments on commit a7e5866

Please sign in to comment.