sidekiq_error_handler.rb 545 B

1234567891011121314151617181920212223242526
  1. # frozen_string_literal: true
  2. class SidekiqErrorHandler
  3. BACKTRACE_LIMIT = 3
  4. def call(*)
  5. yield
  6. rescue Mastodon::HostValidationError
  7. # Do not retry
  8. rescue => e
  9. limit_backtrace_and_raise(e)
  10. ensure
  11. socket = Thread.current[:statsd_socket]
  12. socket&.close
  13. Thread.current[:statsd_socket] = nil
  14. end
  15. private
  16. # rubocop:disable Naming/MethodParameterName
  17. def limit_backtrace_and_raise(e)
  18. e.set_backtrace(e.backtrace.first(BACKTRACE_LIMIT))
  19. raise e
  20. end
  21. # rubocop:enable Naming/MethodParameterName
  22. end