From b3d5e47d9481c2d709d2e60d2054da455d5c6863 Mon Sep 17 00:00:00 2001 From: Justin Coyne Date: Thu, 6 Jul 2017 09:44:49 -0500 Subject: [PATCH] Provide a fallback default version when the network is unavailable --- lib/solr_wrapper.rb | 5 +++++ lib/solr_wrapper/configuration.rb | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/solr_wrapper.rb b/lib/solr_wrapper.rb index 12a4f27..4aa10e8 100644 --- a/lib/solr_wrapper.rb +++ b/lib/solr_wrapper.rb @@ -14,6 +14,11 @@ def self.default_solr_version 'latest' end + # A version we can fallback to if we can't retreive the latest + def self.fallback_solr_version + '6.6.0' + end + def self.default_solr_port '8983' end diff --git a/lib/solr_wrapper/configuration.rb b/lib/solr_wrapper/configuration.rb index b46d237..3e5ed0b 100644 --- a/lib/solr_wrapper/configuration.rb +++ b/lib/solr_wrapper/configuration.rb @@ -156,8 +156,11 @@ def default_configuration_paths end def fetch_latest_version - response = Faraday.get('https://svn.apache.org/repos/asf/lucene/cms/trunk/content/latestversion.mdtext') - response.body.strip + path = 'https://svn.apache.org/repos/asf/lucene/cms/trunk/content/latestversion.mdtext' + Faraday.get(path).body.strip + rescue Faraday::ConnectionFailed + $stderr.puts "Unable to connect to #{path} to retrieve the latest version. Using a default" + SolrWrapper.fallback_solr_version end end end