Add a circuit breaker for ActivityPub deliveries (#7053)
This commit is contained in:
parent
4a9becfca2
commit
d4de2239b0
2
Gemfile
2
Gemfile
@ -35,6 +35,7 @@ gem 'devise-two-factor', '~> 3.0'
|
|||||||
group :pam_authentication, optional: true do
|
group :pam_authentication, optional: true do
|
||||||
gem 'devise_pam_authenticatable2', '~> 9.0'
|
gem 'devise_pam_authenticatable2', '~> 9.0'
|
||||||
end
|
end
|
||||||
|
|
||||||
gem 'net-ldap', '~> 0.10'
|
gem 'net-ldap', '~> 0.10'
|
||||||
gem 'omniauth-cas', '~> 1.1'
|
gem 'omniauth-cas', '~> 1.1'
|
||||||
gem 'omniauth-saml', '~> 1.10'
|
gem 'omniauth-saml', '~> 1.10'
|
||||||
@ -79,6 +80,7 @@ gem 'sidekiq-bulk', '~>0.1.1'
|
|||||||
gem 'simple-navigation', '~> 4.0'
|
gem 'simple-navigation', '~> 4.0'
|
||||||
gem 'simple_form', '~> 3.4'
|
gem 'simple_form', '~> 3.4'
|
||||||
gem 'sprockets-rails', '~> 3.2', require: 'sprockets/railtie'
|
gem 'sprockets-rails', '~> 3.2', require: 'sprockets/railtie'
|
||||||
|
gem 'stoplight', '~> 2.1.3'
|
||||||
gem 'strong_migrations'
|
gem 'strong_migrations'
|
||||||
gem 'tty-command'
|
gem 'tty-command'
|
||||||
gem 'tty-prompt'
|
gem 'tty-prompt'
|
||||||
|
@ -550,6 +550,7 @@ GEM
|
|||||||
net-scp (>= 1.1.2)
|
net-scp (>= 1.1.2)
|
||||||
net-ssh (>= 2.8.0)
|
net-ssh (>= 2.8.0)
|
||||||
statsd-ruby (1.2.1)
|
statsd-ruby (1.2.1)
|
||||||
|
stoplight (2.1.3)
|
||||||
streamio-ffmpeg (3.0.2)
|
streamio-ffmpeg (3.0.2)
|
||||||
multi_json (~> 1.8)
|
multi_json (~> 1.8)
|
||||||
strong_migrations (0.1.9)
|
strong_migrations (0.1.9)
|
||||||
@ -716,6 +717,7 @@ DEPENDENCIES
|
|||||||
simple_form (~> 3.4)
|
simple_form (~> 3.4)
|
||||||
simplecov (~> 0.14)
|
simplecov (~> 0.14)
|
||||||
sprockets-rails (~> 3.2)
|
sprockets-rails (~> 3.2)
|
||||||
|
stoplight (~> 2.1.3)
|
||||||
streamio-ffmpeg (~> 3.0)
|
streamio-ffmpeg (~> 3.0)
|
||||||
strong_migrations
|
strong_migrations
|
||||||
tty-command
|
tty-command
|
||||||
|
@ -12,9 +12,7 @@ class ActivityPub::DeliveryWorker
|
|||||||
@source_account = Account.find(source_account_id)
|
@source_account = Account.find(source_account_id)
|
||||||
@inbox_url = inbox_url
|
@inbox_url = inbox_url
|
||||||
|
|
||||||
perform_request do |response|
|
perform_request
|
||||||
raise Mastodon::UnexpectedResponseError, response unless response_successful? response
|
|
||||||
end
|
|
||||||
|
|
||||||
failure_tracker.track_success!
|
failure_tracker.track_success!
|
||||||
rescue => e
|
rescue => e
|
||||||
@ -30,8 +28,14 @@ class ActivityPub::DeliveryWorker
|
|||||||
request.add_headers(HEADERS)
|
request.add_headers(HEADERS)
|
||||||
end
|
end
|
||||||
|
|
||||||
def perform_request(&block)
|
def perform_request
|
||||||
build_request.perform(&block)
|
light = Stoplight(@inbox_url) do
|
||||||
|
build_request.perform do |response|
|
||||||
|
raise Mastodon::UnexpectedResponseError, response unless response_successful?(response)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
light.run
|
||||||
end
|
end
|
||||||
|
|
||||||
def response_successful?(response)
|
def response_successful?(response)
|
||||||
|
3
config/initializers/stoplight.rb
Normal file
3
config/initializers/stoplight.rb
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
require 'stoplight'
|
||||||
|
|
||||||
|
Stoplight::Light.default_data_store = Stoplight::DataStore::Redis.new(Redis.current)
|
Loading…
Reference in New Issue
Block a user