From 0964741d437849f1cd3431c8fa28d00b377fd54b Mon Sep 17 00:00:00 2001 From: Ben VandenBos Date: Fri, 4 May 2012 15:56:21 -0700 Subject: [PATCH] Fixing potential job-loss race condition --- HISTORY.md | 2 ++ README.markdown | 8 +++++++- lib/resque_scheduler.rb | 10 +++++++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index ae132c0f..e90b9aec 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,6 +1,8 @@ ## * Add support for Resque.inline configuration (carlosantoniodasilva) +* Fixing possible job loss race condition around deleting delayed queues + and enqueuing a job 0 seconds in the future. ## 2.0.0.h (2012-03-19) diff --git a/README.markdown b/README.markdown index 758206aa..17b9f053 100644 --- a/README.markdown +++ b/README.markdown @@ -6,7 +6,13 @@ resque-scheduler Resque-scheduler is an extension to [Resque](http://github.com/defunkt/resque) that adds support for queueing items in the future. -Requires redis >=1.3. +This table explains the version requirements for redis + +| resque-scheduler version | required redis version| +|:-------------------------|----------------------:| +| >= 2.0.0.i | >= 2.2.0 | +| <= 2.0.0.i | >= 1.3 | + Job scheduling is supported in two different way: Recurring (scheduled) and Delayed. diff --git a/lib/resque_scheduler.rb b/lib/resque_scheduler.rb index e6a04f33..837d5ba9 100644 --- a/lib/resque_scheduler.rb +++ b/lib/resque_scheduler.rb @@ -258,12 +258,16 @@ def job_to_hash_with_queue(queue, klass, args) def clean_up_timestamp(key, timestamp) # If the list is empty, remove it. + redis.watch key if 0 == redis.llen(key).to_i - redis.del key - redis.zrem :delayed_queue_schedule, timestamp.to_i + redis.multi do + redis.del key + redis.zrem :delayed_queue_schedule, timestamp.to_i + end + else + redis.unwatch end end - def validate_job!(klass) if klass.to_s.empty? raise Resque::NoClassError.new("Jobs must be given a class.")