Refactor fetching of remote resources (#11251)
This commit is contained in:
parent
d04c584159
commit
5d3feed191
13 changed files with 142 additions and 216 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
class ActivityPub::DeliveryWorker
|
||||
include Sidekiq::Worker
|
||||
include JsonLdHelper
|
||||
|
||||
STOPLIGHT_FAILURE_THRESHOLD = 10
|
||||
STOPLIGHT_COOLDOWN = 60
|
||||
|
@ -32,9 +33,10 @@ class ActivityPub::DeliveryWorker
|
|||
private
|
||||
|
||||
def build_request(http_client)
|
||||
request = Request.new(:post, @inbox_url, body: @json, http_client: http_client)
|
||||
request.on_behalf_of(@source_account, :uri, sign_with: @options[:sign_with])
|
||||
request.add_headers(HEADERS)
|
||||
Request.new(:post, @inbox_url, body: @json, http_client: http_client).tap do |request|
|
||||
request.on_behalf_of(@source_account, :uri, sign_with: @options[:sign_with])
|
||||
request.add_headers(HEADERS)
|
||||
end
|
||||
end
|
||||
|
||||
def perform_request
|
||||
|
@ -53,14 +55,6 @@ class ActivityPub::DeliveryWorker
|
|||
.run
|
||||
end
|
||||
|
||||
def response_successful?(response)
|
||||
(200...300).cover?(response.code)
|
||||
end
|
||||
|
||||
def response_error_unsalvageable?(response)
|
||||
response.code == 501 || ((400...500).cover?(response.code) && ![401, 408, 429].include?(response.code))
|
||||
end
|
||||
|
||||
def failure_tracker
|
||||
@failure_tracker ||= DeliveryFailureTracker.new(@inbox_url)
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue