From ad5b1b92489c925a68691e5e95ae1b8ff350652e Mon Sep 17 00:00:00 2001 From: Joe Carrafa Date: Wed, 11 Dec 2013 15:17:34 -0500 Subject: [PATCH 1/3] resque 1.25+ fails --- resque-lonely_job.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resque-lonely_job.gemspec b/resque-lonely_job.gemspec index 9d78dae..e79e283 100644 --- a/resque-lonely_job.gemspec +++ b/resque-lonely_job.gemspec @@ -14,7 +14,7 @@ Gem::Specification.new do |gem| gem.require_paths = ["lib"] gem.version = Resque::Plugins::LonelyJob::VERSION - gem.add_dependency 'resque', '>= 1.20.0' + gem.add_dependency 'resque', '~> 1.24.0' gem.add_development_dependency 'mock_redis', '~> 0.4.1' gem.add_development_dependency 'rake' gem.add_development_dependency 'rspec' From 83f04f1b28344c9df25e2a3bbe7482f0ddae55e5 Mon Sep 17 00:00:00 2001 From: Joe Carrafa Date: Wed, 11 Dec 2013 16:07:32 -0500 Subject: [PATCH 2/3] remove specified version for mock_redis --- resque-lonely_job.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resque-lonely_job.gemspec b/resque-lonely_job.gemspec index e79e283..912a5b8 100644 --- a/resque-lonely_job.gemspec +++ b/resque-lonely_job.gemspec @@ -15,7 +15,7 @@ Gem::Specification.new do |gem| gem.version = Resque::Plugins::LonelyJob::VERSION gem.add_dependency 'resque', '~> 1.24.0' - gem.add_development_dependency 'mock_redis', '~> 0.4.1' + gem.add_development_dependency 'mock_redis' gem.add_development_dependency 'rake' gem.add_development_dependency 'rspec' gem.add_development_dependency 'debugger' From ee6b325609d3235aaa9d7122dcb4ada3b6a0ff00 Mon Sep 17 00:00:00 2001 From: Joe Carrafa Date: Wed, 11 Dec 2013 16:08:13 -0500 Subject: [PATCH 3/3] update locking mechanism for redis 2.6.12+ --- lib/resque-lonely_job.rb | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) 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)