0
0
Fork 0

Add stoplight for object storage failures, return HTTP 503 (#13043)

This commit is contained in:
Eugen Rochko 2020-12-15 12:55:29 +01:00 committed by GitHub
parent 75d2762fdf
commit 1045549f85
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 34 additions and 2 deletions

View file

@ -39,6 +39,23 @@ module Paperclip
def default_url(style_name = default_style)
@url_generator.for_as_default(style_name)
end
STOPLIGHT_THRESHOLD = 10
STOPLIGHT_COOLDOWN = 30
# We overwrite this method to put a circuit breaker around
# calls to object storage, to stop hitting APIs that are slow
# to respond or don't respond at all and as such minimize the
# impact of object storage outages on application throughput
def save
Stoplight('object-storage') { super }.with_threshold(STOPLIGHT_THRESHOLD).with_cool_off_time(STOPLIGHT_COOLDOWN).with_error_handler do |error, handle|
if error.is_a?(Seahorse::Client::NetworkingError)
handle.call(error)
else
raise error
end
end.run
end
end
end