1
0

sidekiq_error_handler.rb 484 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(exception)
  17. exception.set_backtrace(exception.backtrace.first(BACKTRACE_LIMIT))
  18. raise exception
  19. end
  20. end