Skip to content

Commit

Permalink
Fixing potential job-loss race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
bvandenbos committed May 4, 2012
1 parent 32e8154 commit 0964741
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 2 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
8 changes: 7 additions & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 7 additions & 3 deletions lib/resque_scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down

0 comments on commit 0964741

Please sign in to comment.