about summary refs log tree commit diff
path: root/app/workers
diff options
context:
space:
mode:
authorThibaut Girka <thib@sitedethib.com>2018-05-19 22:41:10 +0200
committerThibaut Girka <thib@sitedethib.com>2018-05-19 22:41:10 +0200
commitb481e4fac1c564b8008f6f1d0eea1727ec9faa08 (patch)
tree6917de2e59e69f5ad0dc9b1471a7c7c8659c1af8 /app/workers
parent625c4f36ef394215e65e19157bfaf60e7de94b5f (diff)
parent6aa5ea1b5dff54941682cb006ac2b11ab7b77988 (diff)
Merge branch 'master' into glitch-soc/merge-upstream
Conflicts:
	config/locales/simple_form.ja.yml
Diffstat (limited to 'app/workers')
-rw-r--r--app/workers/activitypub/delivery_worker.rb15
1 files changed, 12 insertions, 3 deletions
diff --git a/app/workers/activitypub/delivery_worker.rb b/app/workers/activitypub/delivery_worker.rb
index adffd1d3b..323a9f85b 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,15 +34,21 @@ 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
+    (200...300).cover?(response.code)
+  end
+
+  def response_error_unsalvageable?(response)
+    (400...500).cover?(response.code) && response.code != 429
   end
 
   def failure_tracker