sidekiq_error_handler.rb 452 B

123456789101112131415161718192021222324
  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. def limit_backtrace_and_raise(e)
  17. e.set_backtrace(e.backtrace.first(BACKTRACE_LIMIT))
  18. raise e
  19. end
  20. end