Skip to content

Commit

Permalink
Merge pull request #35 from omc/dds/error-msg
Browse files Browse the repository at this point in the history
Provide configuration help
  • Loading branch information
drusellers authored Nov 26, 2018
2 parents 2b52903 + 010c991 commit 110bb95
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/searchyll.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@

Jekyll::Hooks.register(:site, :pre_render) do |site|
config = Searchyll::Configuration.new(site)
if config.elasticsearch_url && !config.elasticsearch_url.empty?
if config.valid?
puts "setting up indexer hook with url #{config.elasticsearch_url.inspect}"
indexers[site] = Searchyll::Indexer.new(config)
indexers[site].start
else
puts 'No ElasticSearch URL provided, skipping indexing...'
puts 'Invalid Elasticsearch configuration provided, skipping indexing...'
config.reasons.each do |r|
puts " #{r}"
end
end
end

Expand Down
33 changes: 33 additions & 0 deletions lib/searchyll/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Searchyll
class Configuration
attr_accessor :site

def initialize(site)
self.site = site
end
Expand All @@ -11,6 +12,38 @@ def elasticsearch_url
((site.config||{})['elasticsearch']||{})['url']
end

def valid?
elasticsearch_url && !elasticsearch_url.empty? && elasticsearch_url.start_with?('http')
end

def reasons
reasons = []
if elasticsearch_url && elasticsearch_url.empty?
reasons << 'No Elasticsearch url configured'
reasons << ' Looked in ENV[BONSAI_URL]'
reasons << ' Looked in ENV[ELASTICSEARCH_URL]'
reasons << ' Looked in _config.elasticsearch.url'
elsif ! elasticsearch_url.start_with? 'http'
reasons << "Elasticsearch url must start with 'http' or 'https'"
reasons << " Current Value: #{elasticsearch_url}"
reasons << " Current Source: #{elasticsearch_url_source}"
end

reasons
end

def elasticsearch_url_source
if ENV['BONSAI_URL']
'ENV[BONSAI_URL]'
elsif ENV['ELASTICSEARCH_URL']
'ENV[ELASTICSEARCH_URL]'
elsif ((site.config||{})['elasticsearch']||{})['url']
'CONFIG'
else
'NOT FOUND'
end
end

# Getter for the number of primary shards
def elasticsearch_number_of_shards
site.config['elasticsearch']['number_of_shards'] || 1
Expand Down

0 comments on commit 110bb95

Please sign in to comment.