Skip to content

Commit

Permalink
Merge remote-tracking branch 'github/master' into add-logging
Browse files Browse the repository at this point in the history
Conflicts:
	lib/resque/plugins/retry.rb
  • Loading branch information
davetron5000 committed Apr 29, 2014
2 parents e0fee8a + 0382f3f commit c4296d6
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/resque/plugins/retry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def before_perform_retry(*args)
Resque.redis.setnx(retry_key, -1) # default to -1 if not set.
@retry_attempt = Resque.redis.incr(retry_key) # increment by 1.
log_message "attempt: #{@retry_attempt} set in Redis", args
@retry_attempt
Resque.redis.expire(retry_key, @retry_delay.to_i + @expire_retry_key_after.to_i) if @expire_retry_key_after
end

# Resque after_perform hook
Expand Down
10 changes: 10 additions & 0 deletions test/multiple_failure_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,16 @@ def test_custom_retry_identifier_job
assert_equal 1, MockFailureBackend.errors.size
end

def test_failure_with_retry_bumps_key_expire
Resque.enqueue(FailFiveTimesWithExpiryJob, 'foo')
retry_key = FailFiveTimesWithExpiryJob.redis_retry_key('foo')

Resque.redis.expects(:expire).times(4).with(retry_key, 3600)
4.times do
perform_next_job(@worker)
end
end

def teardown
Resque::Failure.backend = @old_failure_backend
end
Expand Down
5 changes: 5 additions & 0 deletions test/retry_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,9 @@ def test_retry_delay
assert_equal 13, PerExceptionClassRetryCountJob.retry_delay(Timeout::Error)
end

def test_expire_key_set
Resque.redis.expects(:expire).once.with(ExpiringJob.redis_retry_key('expiry_test'), 3600)
Resque.enqueue(ExpiringJob, 'expiry_test')
perform_next_job(@worker)
end
end
19 changes: 19 additions & 0 deletions test/test_jobs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ def self.perform(*args)
end
end

class ExpiringJob
extend Resque::Plugins::Retry
@queue = :testing
@expire_retry_key_after = 60 * 60

def self.perform(*args)
end
end

class RetryDefaultSettingsJob
extend Resque::Plugins::Retry
@queue = :testing
Expand Down Expand Up @@ -135,6 +144,16 @@ def self.perform(*args)
end
end

class FailFiveTimesWithExpiryJob < RetryDefaultsJob
@queue = :testing
@retry_limit = 6
@expire_retry_key_after = 60 * 60

def self.perform(*args)
raise if retry_attempt <= 4
end
end

class ExponentialBackoffJob < RetryDefaultsJob
extend Resque::Plugins::ExponentialBackoff
@queue = :testing
Expand Down

0 comments on commit c4296d6

Please sign in to comment.