diff --git a/lib/resque-lonely_job.rb b/lib/resque-lonely_job.rb index 11ee9bd..18d0afe 100644 --- a/lib/resque-lonely_job.rb +++ b/lib/resque-lonely_job.rb @@ -5,10 +5,6 @@ module Plugins module LonelyJob LOCK_TIMEOUT = 60 * 60 * 24 * 5 # 5 days - def lock_timeout - Time.now.to_i + LOCK_TIMEOUT + 1 - end - # Overwrite this method to uniquely identify which mutex should be used # for a resque worker. def redis_key(*args) @@ -16,15 +12,10 @@ def redis_key(*args) end def can_lock_queue?(*args) - now = Time.now.to_i key = redis_key(*args) - timeout = lock_timeout - # Per http://redis.io/commands/setnx - return true if Resque.redis.setnx(key, timeout) - return false if Resque.redis.get(key).to_i > now - return true if Resque.redis.getset(key, timeout).to_i <= now - return false + # Per http://redis.io/commands/set + Resque.redis.set key, 'anystring', nx: true, ex: LOCK_TIMEOUT end def unlock_queue(*args) diff --git a/resque-lonely_job.gemspec b/resque-lonely_job.gemspec index 9d78dae..912a5b8 100644 --- a/resque-lonely_job.gemspec +++ b/resque-lonely_job.gemspec @@ -14,8 +14,8 @@ Gem::Specification.new do |gem| gem.require_paths = ["lib"] gem.version = Resque::Plugins::LonelyJob::VERSION - gem.add_dependency 'resque', '>= 1.20.0' - gem.add_development_dependency 'mock_redis', '~> 0.4.1' + gem.add_dependency 'resque', '~> 1.24.0' + gem.add_development_dependency 'mock_redis' gem.add_development_dependency 'rake' gem.add_development_dependency 'rspec' gem.add_development_dependency 'debugger'