diff --git a/lib/resque/integration.rb b/lib/resque/integration.rb index 0771f42..8699c34 100644 --- a/lib/resque/integration.rb +++ b/lib/resque/integration.rb @@ -122,7 +122,7 @@ def retrys(options = {}) @retry_exceptions = @retry_exceptions && @retry_exceptions.dup || {} @retry_exceptions = @retry_exceptions.product([@retry_delay]).to_h if @retry_exceptions.is_a? Array - @retry_exceptions.reverse_merge!(Rails.application.config.temporary_exceptions) + @retry_exceptions.reverse_merge!(Resque.config.temporary_exceptions) end @expire_retry_key_after = options.fetch(:expire_retry_key_after, 1.hour.seconds) diff --git a/lib/resque/integration/configuration.rb b/lib/resque/integration/configuration.rb index d159f6b..0ff67b3 100644 --- a/lib/resque/integration/configuration.rb +++ b/lib/resque/integration/configuration.rb @@ -209,6 +209,24 @@ def god_log_level self['resque.god_log_level'] || 'info' end + # Public: Temporary exceptions. + # + # Examples + # + # temporary_exceptions + # # => {PG::TRDeadlockDetected => 20, Net::OpenTimeout => 123} + # + # Returns Hash. + def temporary_exceptions + return @temporary_exceptions if defined?(@temporary_exceptions) + + return {} unless self['resque.temporary_exceptions'] + + @temporary_exceptions = self['resque.temporary_exceptions'].each_with_object({}) do |(key, value), result| + result[key.constantize] = value + end + end + private def load(path) if File.exists?(path) diff --git a/lib/resque/integration/engine.rb b/lib/resque/integration/engine.rb index 76c6af2..dedf0e9 100644 --- a/lib/resque/integration/engine.rb +++ b/lib/resque/integration/engine.rb @@ -73,7 +73,7 @@ class Engine < Rails::Engine end # Глушим ошибки, по которым происходит автоматический перезапуск - initializer 'resque-integration.retrys' do |app| + initializer 'resque-integration.retrys' do require 'resque/failure' require 'resque/failure/redis' @@ -89,11 +89,6 @@ class Engine < Rails::Engine end Resque::Failure.backend = Resque::Failure::MultipleWithRetrySuppression - # Hash - temporary exceptions - # - # example: - # {PG::TRDeadlockDetected => 20, Net::OpenTimeout => 123} - app.config.temporary_exceptions = {} end initializer "resque-integration.extensions" do diff --git a/spec/resque/integration/configuration_spec.rb b/spec/resque/integration/configuration_spec.rb index a2f6749..813d3b6 100644 --- a/spec/resque/integration/configuration_spec.rb +++ b/spec/resque/integration/configuration_spec.rb @@ -54,6 +54,18 @@ it { expect(config.run_at_exit_hooks?).to be_falsey } end end + + describe '#temporary_exceptions' do + context 'when default' do + it { expect(config.temporary_exceptions).to eq({}) } + end + + context 'when defined' do + let(:config_yaml) { {'resque' => {'temporary_exceptions' => {'StandardError' => 12}}} } + + it { expect(config.temporary_exceptions).to eq(StandardError => 12) } + end + end end describe Resque::Integration::Configuration::Notifier do