Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix race-condition in scheduler thread #30

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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