rescue Net::OpenTimeout, Net::ReadTimeout
try_again_later(order)
end
Slide 6
Exceptions
def call(order)
do something…
rescue Net::OpenTimeout, Net::ReadTimeout
try_again_later(order)
rescue Faraday::ConnectionFailed => error
if error.message == “execution expired”
try_again_later(order)
end
end
Slide 7
=== matcher in Ruby
Slide 8
module FaradayTimeoutErrorMatcher
def self.===(error)
error.is_a?(Faraday::ConnectionFailed) &&
error.message == “execution expired”
end
end
Slide 9
🎉
def call(order)
do something…
rescue Net::OpenTimeout, Net::ReadTimeout, FaradayTimeoutErrorMatcher
try_again_later(order)
end
Slide 10
module NetworkTimeoutErrorMatcher
def self.===(error)
case error
when Faraday::ConnectionFailed
error.message == “execution expired”
when Net::OpenTimeout, Net::ReadTimeout
true
end
end
end
Slide 11
🎉🎉🎉
def call(order)
do something…
rescue NetworkTimeoutErrorMatcher
try_again_later(order)
end
Slide 12
Retriable gem
def call(order)
retriable(on: NetworkTimeoutErrorMatcher) do
# do something…
end
end