Skip to content

Commit

Permalink
feat: move temporary_exceptions to yml config
Browse files Browse the repository at this point in the history
  • Loading branch information
taleksei committed Aug 14, 2018
1 parent 68fcea3 commit 3fa8ce0
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/resque/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions lib/resque/integration/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 1 addition & 6 deletions lib/resque/integration/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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
Expand Down
12 changes: 12 additions & 0 deletions spec/resque/integration/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3fa8ce0

Please sign in to comment.