0
0
Fork 0

Update stoplight to version 4.1.0 (#28366)

This commit is contained in:
Matt Jankowski 2024-04-02 11:47:40 -04:00 committed by GitHub
parent 921c4c1273
commit edde54e991
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 30 additions and 33 deletions

View file

@ -59,7 +59,7 @@ class ActivityPub::DeliveryWorker
end
def perform_request
light = Stoplight(@inbox_url) do
stoplight_wrapper.run do
request_pool.with(@host) do |http_client|
build_request(http_client).perform do |response|
raise Mastodon::UnexpectedResponseError, response unless response_successful?(response) || response_error_unsalvageable?(response)
@ -68,10 +68,12 @@ class ActivityPub::DeliveryWorker
end
end
end
end
light.with_threshold(STOPLIGHT_FAILURE_THRESHOLD)
.with_cool_off_time(STOPLIGHT_COOLDOWN)
.run
def stoplight_wrapper
Stoplight(@inbox_url)
.with_threshold(STOPLIGHT_FAILURE_THRESHOLD)
.with_cool_off_time(STOPLIGHT_COOLDOWN)
end
def failure_tracker

View file

@ -11,7 +11,7 @@ class Import::RelationshipWorker
def perform(account_id, target_account_uri, relationship, options)
from_account = Account.find(account_id)
target_domain = domain(target_account_uri)
target_account = stoplight_wrap_request(target_domain) { ResolveAccountService.new.call(target_account_uri, { check_delivery_availability: true }) }
target_account = stoplight_wrapper(target_domain).run { ResolveAccountService.new.call(target_account_uri, { check_delivery_availability: true }) }
options.symbolize_keys!
return if target_account.nil?
@ -43,16 +43,15 @@ class Import::RelationshipWorker
TagManager.instance.local_domain?(domain) ? nil : TagManager.instance.normalize_domain(domain)
end
def stoplight_wrap_request(domain, &block)
def stoplight_wrapper(domain)
if domain.present?
Stoplight("source:#{domain}", &block)
Stoplight("source:#{domain}")
.with_fallback { nil }
.with_threshold(1)
.with_cool_off_time(5.minutes.seconds)
.with_error_handler { |error, handle| error.is_a?(HTTP::Error) || error.is_a?(OpenSSL::SSL::SSLError) ? handle.call(error) : raise(error) }
.run
else
yield
Stoplight('domain-blank')
end
end
end