From 1ff2f4eb5839a5d6da61f0c7d47e0a697954cd3c Mon Sep 17 00:00:00 2001 From: "Andrew N. Shalaev" Date: Thu, 31 Aug 2017 12:25:50 +0500 Subject: [PATCH] fix: keep meta_id on_failure_retry callback if Resque::DirtyExit occurred https://jira.railsc.ru/browse/BPC-10431 --- lib/resque/integration/unique.rb | 12 ++++++++++++ spec/resque/integration/unique_spec.rb | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/lib/resque/integration/unique.rb b/lib/resque/integration/unique.rb index dc534f9..0cc2abd 100644 --- a/lib/resque/integration/unique.rb +++ b/lib/resque/integration/unique.rb @@ -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 @@ -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) && diff --git a/spec/resque/integration/unique_spec.rb b/spec/resque/integration/unique_spec.rb index 002dc4b..2839ea9 100644 --- a/spec/resque/integration/unique_spec.rb +++ b/spec/resque/integration/unique_spec.rb @@ -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 @@ -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