Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ gem "resque"
group :development do
gem "turn"
gem "rake"
gem 'json'
end
1 change: 0 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'rake/testtask'
require 'rake/rdoctask'

def command?(command)
system("type #{command} > /dev/null")
Expand Down
10 changes: 8 additions & 2 deletions lib/resque/plugins/lock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ def before_enqueue_lock(*args)
# (we cannot acquire the lock during the timeout period)
return false if now <= Resque.redis.get(key).to_i

# otherwise set the timeout and ensure that no other worker has
# acquired the lock
# otherwise dequeue the job holding the current lock and reset the
# timeout to ensure that no other worker has acquired the lock
Resque.dequeue(self, *args)
now > Resque.redis.getset(key, timeout).to_i
end

Expand All @@ -84,6 +85,11 @@ def around_perform_lock(*args)
Resque.redis.del(lock(*args))
end
end

# Some errors may not be capture by above `ensure'. Handle it here.
def on_failure_lock(exception, *args)
Resque.redis.del(lock(*args))
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion resque-lock.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = "resque-lock"
s.version = "1.1.0"
s.version = "1.1.3"
s.date = Time.now.strftime('%Y-%m-%d')
s.summary = "A Resque plugin for ensuring only one instance of your job is queued at a time."
s.homepage = "http://github.com/defunkt/resque-lock"
Expand Down
2 changes: 1 addition & 1 deletion test/lock_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ def test_deadlock

sleep 3
Resque.enqueue(Job)
assert_equal 2, Resque.redis.llen('queue:lock_test')
assert_equal 1, Resque.redis.llen('queue:lock_test')
end
end