Skip to content

Commit

Permalink
use breakers for MVI
Browse files Browse the repository at this point in the history
  • Loading branch information
aub committed Nov 6, 2016
1 parent ec23538 commit 8a916ca
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
5 changes: 4 additions & 1 deletion config/initializers/breakers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
require 'evss/common_service'
require 'evss/documents_service'

require 'mvi/service'

# Read the redis config, create a connection and a namespace for breakers
redis_config = Rails.application.config_for(:redis).freeze
redis = Redis.new(redis_config['redis'])
Expand All @@ -17,7 +19,8 @@
SM::Configuration.instance.breakers_service,
EVSS::ClaimsService.breakers_service,
EVSS::CommonService.breakers_service,
EVSS::DocumentsService.breakers_service
EVSS::DocumentsService.breakers_service,
MVI::Service.breakers_service
]

plugin = Breakers::StatsdPlugin.new
Expand Down
19 changes: 18 additions & 1 deletion lib/mvi/service.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true
require 'savon'
require 'mvi/settings'
require_relative 'responses/find_candidate'

module MVI
Expand Down Expand Up @@ -49,10 +50,26 @@ def find_candidate(message)
raise MVI::ServiceError, 'MVI connection failed'
end

def self.breakers_service
path = URI.parse(options[:url]).path
host = URI.parse(options[:url]).host
matcher = proc do |request_env|
request_env.url.host == host && request_env.url.path =~ /^#{path}/
end

@service = Breakers::Service.new(
name: 'MVI',
request_matcher: matcher
)
end

private

def connection
@conn ||= Faraday.new(MVI::Service.options)
@conn ||= Faraday.new(MVI::Service.options) do |conn|
conn.use :breakers
conn.adapter Faraday.default_adapter
end
end

def call(operation, body)
Expand Down
4 changes: 4 additions & 0 deletions config/initializers/mvi_settings.rb → lib/mvi/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@ module Settings
SSL_CERT = begin
OpenSSL::X509::Certificate.new(File.read(ENV['MVI_CLIENT_CERT_PATH']))
rescue => e
# :nocov:
Rails.logger.warn "Could not load MVI SSL cert: #{e.message}"
raise e if Rails.env.production?
nil
# :nocov:
end
SSL_KEY = begin
OpenSSL::PKey::RSA.new(File.read(ENV['MVI_CLIENT_KEY_PATH']))
rescue => e
# :nocov:
Rails.logger.warn "Could not load MVI SSL key: #{e.message}"
raise e if Rails.env.production?
nil
# :nocov:
end
end
end
7 changes: 7 additions & 0 deletions spec/lib/mvi/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@
expect { subject.find_candidate(message) }.to raise_error(MVI::RecordNotFound)
end
end

context 'with an ongoing breakers outage' do
it 'returns the correct thing' do
MVI::Service.breakers_service.begin_forced_outage!
expect { subject.find_candidate(message) }.to raise_error(Breakers::OutageException)
end
end
end

context 'when MVI returns 500 but VAAFI sends 200' do
Expand Down

0 comments on commit 8a916ca

Please sign in to comment.