Module: SidekiqRemappableErrors::ClassMethods

Defined in:
lib/sidekiq_remappable_errors.rb

Instance Method Summary collapse

Instance Method Details

#initialize_remappable_errorsObject



29
30
31
32
33
34
# File 'lib/sidekiq_remappable_errors.rb', line 29

def initialize_remappable_errors
  define_singleton_method(:error_matchers_store) { [] }
  define_singleton_method(:remappable_errors_options_store) {
    { max_remaps: 5 }
  }
end

#remappable_errors(errors) ⇒ Object

2D array of error class + message regex. If a raised error matches that class and it’s error matches that regex the class will be remapped.

e.g. remappable_errors [

[ ActiveRecord::RecordNotFound, /trainer/i ],
[ FlakyService::ServiceUnvailable, // ],

]



47
48
49
50
51
52
# File 'lib/sidekiq_remappable_errors.rb', line 47

def remappable_errors(errors)
  current_errors = error_matchers_store
  new_errors = errors.map { |error| ErrorMatcher.new(error) }

  define_singleton_method(:error_matchers_store) { current_errors + new_errors }
end

#remappable_errors_options(**opts) ⇒ Object

Define remapping behavior

e.g. remappable_errors_options max_remaps: <<Integer>>



59
60
61
62
63
64
65
# File 'lib/sidekiq_remappable_errors.rb', line 59

def remappable_errors_options(**opts)
  current_options = remappable_errors_options_store

  define_singleton_method(:remappable_errors_options_store) {
    current_options.merge(opts)
  }
end