Update stoplight to version 5.3.1 (#35129)
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class BulkImportRowService
|
||||
STOPLIGHT_COOL_OFF_TIME = 5.minutes.seconds
|
||||
STOPLIGHT_THRESHOLD = 1
|
||||
|
||||
def call(row)
|
||||
@account = row.bulk_import.account
|
||||
@data = row.data
|
||||
@@ -10,7 +13,7 @@ class BulkImportRowService
|
||||
when :following, :blocking, :muting, :lists
|
||||
target_acct = @data['acct']
|
||||
target_domain = domain(target_acct)
|
||||
@target_account = stoplight_wrapper(target_domain).run { ResolveAccountService.new.call(target_acct, { check_delivery_availability: true }) }
|
||||
@target_account = stoplight_wrapper(target_domain).run(stoplight_fallback) { ResolveAccountService.new.call(target_acct, { check_delivery_availability: true }) }
|
||||
return false if @target_account.nil?
|
||||
when :bookmarks
|
||||
target_uri = @data['uri']
|
||||
@@ -18,7 +21,7 @@ class BulkImportRowService
|
||||
@target_status = ActivityPub::TagManager.instance.uri_to_resource(target_uri, Status)
|
||||
return false if @target_status.nil? && ActivityPub::TagManager.instance.local_uri?(target_uri)
|
||||
|
||||
@target_status ||= stoplight_wrapper(target_domain).run { ActivityPub::FetchRemoteStatusService.new.call(target_uri) }
|
||||
@target_status ||= stoplight_wrapper(target_domain).run(stoplight_fallback) { ActivityPub::FetchRemoteStatusService.new.call(target_uri) }
|
||||
return false if @target_status.nil?
|
||||
end
|
||||
|
||||
@@ -51,13 +54,18 @@ class BulkImportRowService
|
||||
TagManager.instance.local_domain?(domain) ? nil : TagManager.instance.normalize_domain(domain)
|
||||
end
|
||||
|
||||
def stoplight_fallback
|
||||
->(error) {}
|
||||
end
|
||||
|
||||
def stoplight_wrapper(domain)
|
||||
if domain.present?
|
||||
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) }
|
||||
Stoplight(
|
||||
"source:#{domain}",
|
||||
cool_off_time: STOPLIGHT_COOL_OFF_TIME,
|
||||
threshold: STOPLIGHT_THRESHOLD,
|
||||
tracked_errors: [HTTP::Error, OpenSSL::SSL::SSLError]
|
||||
)
|
||||
else
|
||||
Stoplight('domain-blank')
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user