Skip to content

Commit

Permalink
fix: keep meta_id on_failure_retry callback if Resque::DirtyExit occu…
Browse files Browse the repository at this point in the history
  • Loading branch information
ashalaev committed Aug 31, 2017
1 parent d3d423f commit 1ff2f4e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/resque/integration/unique.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ def self.extended(base)
base.singleton_class.class_eval do
alias_method_chain :enqueue, :check
end

if base.respond_to?(:on_failure_retry)
base.singleton_class.class_eval do
alias_method_chain(:on_failure_retry, :keep_meta_id)
end
end
end

module ClassMethods
Expand Down Expand Up @@ -113,6 +119,12 @@ def on_failure_lock(e, *args)
unlock(*args)
end

def on_failure_retry_with_keep_meta_id(e, *args)
@meta_id = args.first if e.is_a?(Resque::DirtyExit)

on_failure_retry_without_keep_meta_id(e, *args)
end

# Before dequeue check if job is running
def before_dequeue_lock(*args)
(meta_id = args.first) &&
Expand Down
7 changes: 7 additions & 0 deletions spec/resque/integration/unique_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ class JobUniqueWithRetry
include Resque::Integration
extend Resque::Plugins::Retry

@retry_limit = 2
@retry_delay = 1
@retry_exceptions = [IOError]

unique do |foo_var, params|
params[:foo]
end
Expand All @@ -154,5 +158,8 @@ def self.execute(foo_var, params)

it do
expect { worker.unregister_worker }.not_to raise_error

expect(Resque::Failure.count).to eq 1
expect(Resque::Failure.all['exception']).to eq 'Resque::DirtyExit'
end
end

0 comments on commit 1ff2f4e

Please sign in to comment.