From 97f02f2c088f2d3ac6f1232f995cb99aac8df776 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sat, 19 May 2018 00:23:19 +0200 Subject: Do not raise delivery failure on 4xx errors, increase stoplight threshold (#7541) * Do not raise delivery failure on 4xx errors, increase stoplight threshold Stoplight failure threshold from 3 to 10 Status code 429 will raise a failure/get retried * Oops --- app/workers/activitypub/delivery_worker.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'app/workers') diff --git a/app/workers/activitypub/delivery_worker.rb b/app/workers/activitypub/delivery_worker.rb index adffd1d3b..9b278eb72 100644 --- a/app/workers/activitypub/delivery_worker.rb +++ b/app/workers/activitypub/delivery_worker.rb @@ -3,6 +3,9 @@ class ActivityPub::DeliveryWorker include Sidekiq::Worker + STOPLIGHT_FAILURE_THRESHOLD = 10 + STOPLIGHT_COOLDOWN = 60 + sidekiq_options queue: 'push', retry: 16, dead: false HEADERS = { 'Content-Type' => 'application/activity+json' }.freeze @@ -31,17 +34,23 @@ class ActivityPub::DeliveryWorker def perform_request light = Stoplight(@inbox_url) do build_request.perform do |response| - raise Mastodon::UnexpectedResponseError, response unless response_successful?(response) + raise Mastodon::UnexpectedResponseError, response unless response_successful?(response) || response_error_unsalvageable?(response) end end - light.run + light.with_threshold(STOPLIGHT_FAILURE_THRESHOLD) + .with_cool_off_time(STOPLIGHT_COOLDOWN) + .run end def response_successful?(response) response.code > 199 && response.code < 300 end + def response_error_unsalvageable?(response) + response.code > 399 && response.code < 500 && response.code != 429 + end + def failure_tracker @failure_tracker ||= DeliveryFailureTracker.new(@inbox_url) end -- cgit From 587da93152aa68f4ebe3285155aea5642f517d40 Mon Sep 17 00:00:00 2001 From: takayamaki Date: Sat, 19 May 2018 21:47:44 +0900 Subject: checking http status code with range (#7544) --- app/workers/activitypub/delivery_worker.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/workers') diff --git a/app/workers/activitypub/delivery_worker.rb b/app/workers/activitypub/delivery_worker.rb index 9b278eb72..323a9f85b 100644 --- a/app/workers/activitypub/delivery_worker.rb +++ b/app/workers/activitypub/delivery_worker.rb @@ -44,11 +44,11 @@ class ActivityPub::DeliveryWorker end def response_successful?(response) - response.code > 199 && response.code < 300 + (200...300).cover?(response.code) end def response_error_unsalvageable?(response) - response.code > 399 && response.code < 500 && response.code != 429 + (400...500).cover?(response.code) && response.code != 429 end def failure_tracker -- cgit