Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get the retry_attempt for DirtyExit failures, where perform isn't called. #61

Merged
merged 2 commits into from
Aug 12, 2014
Merged
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
8 changes: 6 additions & 2 deletions lib/resque/plugins/retry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,13 @@ def after_perform_retry(*args)
# @api private
def on_failure_retry(exception, *args)
log_message 'on_failure_retry', args, exception
if @on_failure_retry_hook_already_called
if exception.is_a?(Resque::DirtyExit)
# This hook is called from a worker processes, not the job process
# that failed with a DirtyExit, so @retry_attempt wasn't set yet
@retry_attempt = Resque.redis.get(redis_retry_key(*args)).to_i
elsif @on_failure_retry_hook_already_called
log_message 'on_failure_retry_hook_already_called', args, exception
return
return
end

if retry_criteria_valid?(exception, *args)
Expand Down
18 changes: 18 additions & 0 deletions test/retry_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,22 @@ def test_expire_key_setting_on_the_fly
perform_next_job(@worker)
end
end

if Process.respond_to?(:fork) && Gem::Version.new(Resque::VERSION) >= Gem::Version.new('1.20.0')
def test_retry_on_dirty_exit
Resque.enqueue(RetryKilledJob)
RetryKilledJob.expects(:clean_retry_key).once
2.times do
job = @worker.reserve
child = fork do
Resque.redis.client.reconnect
job.perform
end
Process.waitpid(child)
job.fail(Resque::DirtyExit.new)
end

assert_equal nil, @worker.reserve
end
end
end
9 changes: 9 additions & 0 deletions test/test_jobs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -503,3 +503,12 @@ class FailsDuringConnectJob < RetryDefaultsJob
@retry_limit = 3
@retry_delay = 10
end

class RetryKilledJob
extend Resque::Plugins::Retry
@queue = :testing

def self.perform(*args)
Process.kill("KILL", Process.pid)
end
end