2018-02-24 18:16:11 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class SidekiqErrorHandler
|
2020-05-10 09:30:27 +01:00
|
|
|
BACKTRACE_LIMIT = 3
|
|
|
|
|
2018-02-24 18:16:11 +00:00
|
|
|
def call(*)
|
|
|
|
yield
|
2019-07-02 00:01:17 +01:00
|
|
|
rescue Mastodon::HostValidationError
|
2018-02-24 18:16:11 +00:00
|
|
|
# Do not retry
|
2020-05-10 09:30:27 +01:00
|
|
|
rescue => e
|
|
|
|
limit_backtrace_and_raise(e)
|
2019-07-02 00:01:17 +01:00
|
|
|
ensure
|
|
|
|
socket = Thread.current[:statsd_socket]
|
|
|
|
socket&.close
|
|
|
|
Thread.current[:statsd_socket] = nil
|
2018-02-24 18:16:11 +00:00
|
|
|
end
|
2020-05-10 09:30:27 +01:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2021-12-26 23:47:20 +00:00
|
|
|
def limit_backtrace_and_raise(exception)
|
|
|
|
exception.set_backtrace(exception.backtrace.first(BACKTRACE_LIMIT))
|
|
|
|
raise exception
|
2020-05-10 09:30:27 +01:00
|
|
|
end
|
2018-02-24 18:16:11 +00:00
|
|
|
end
|