This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
2018-02-24 10:16:11 -08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class SidekiqErrorHandler
|
2020-05-10 01:30:27 -07:00
|
|
|
BACKTRACE_LIMIT = 3
|
|
|
|
|
2018-02-24 10:16:11 -08:00
|
|
|
def call(*)
|
|
|
|
yield
|
2019-07-01 16:01:17 -07:00
|
|
|
rescue Mastodon::HostValidationError
|
2018-02-24 10:16:11 -08:00
|
|
|
# Do not retry
|
2020-05-10 01:30:27 -07:00
|
|
|
rescue => e
|
|
|
|
limit_backtrace_and_raise(e)
|
2019-07-01 16:01:17 -07:00
|
|
|
ensure
|
|
|
|
socket = Thread.current[:statsd_socket]
|
|
|
|
socket&.close
|
|
|
|
Thread.current[:statsd_socket] = nil
|
2018-02-24 10:16:11 -08:00
|
|
|
end
|
2020-05-10 01:30:27 -07:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def limit_backtrace_and_raise(e)
|
|
|
|
e.set_backtrace(e.backtrace.first(BACKTRACE_LIMIT))
|
|
|
|
raise e
|
|
|
|
end
|
2018-02-24 10:16:11 -08:00
|
|
|
end
|