Commit d2018921 by Clinton Blackburn Committed by Clinton Blackburn

Removed index mapping update at startup

We should not be updating the mapping every time the application is started.
parent 0b4e2ed7
...@@ -27,17 +27,34 @@ if ENV["ENABLE_GC_PROFILER"] ...@@ -27,17 +27,34 @@ if ENV["ENABLE_GC_PROFILER"]
GC::Profiler.enable GC::Profiler.enable
end end
def get_logger(progname, threshold=nil)
logger = Logger.new(STDERR)
logger.progname = progname
logger.level = threshold || Logger::INFO
logger
end
application_yaml = ERB.new(File.read("config/application.yml")).result() application_yaml = ERB.new(File.read("config/application.yml")).result()
CommentService.config = YAML.load(application_yaml).with_indifferent_access CommentService.config = YAML.load(application_yaml).with_indifferent_access
# Raise sinatra-param exceptions so that we can process, and respond to, them appropriately # Raise sinatra-param exceptions so that we can process, and respond to, them appropriately
set :raise_sinatra_param_exceptions, true set :raise_sinatra_param_exceptions, true
# Setup Mongo
Mongoid.load!("config/mongoid.yml", environment) Mongoid.load!("config/mongoid.yml", environment)
Mongoid.logger.level = Logger::INFO Mongoid.logger.level = Logger::INFO
Mongo::Logger.logger.level = ENV["ENABLE_MONGO_DEBUGGING"] ? Logger::DEBUG : Logger::INFO Mongo::Logger.logger.level = ENV["ENABLE_MONGO_DEBUGGING"] ? Logger::DEBUG : Logger::INFO
# set up i18n # Setup Elasticsearch
# NOTE (CCB): If you want to see all data sent to Elasticsearch (e.g. for debugging purposes), set the tracer argument
# to the value of a logger.
# Example: Elascisearch.Client.new(tracer: get_logger('elasticsearch.tracer'))
Elasticsearch::Model.client = Elasticsearch::Client.new(
host: CommentService.config[:elasticsearch_server],
logger: get_logger('elasticsearch', Logger::WARN)
)
# Setup i18n
I18n.load_path += Dir[File.join(File.dirname(__FILE__), 'locale', '*.yml').to_s] I18n.load_path += Dir[File.join(File.dirname(__FILE__), 'locale', '*.yml').to_s]
I18n.default_locale = CommentService.config[:default_locale] I18n.default_locale = CommentService.config[:default_locale]
I18n.enforce_available_locales = false I18n.enforce_available_locales = false
...@@ -54,16 +71,6 @@ Dir[File.dirname(__FILE__) + '/lib/**/*.rb'].each { |file| require file } ...@@ -54,16 +71,6 @@ Dir[File.dirname(__FILE__) + '/lib/**/*.rb'].each { |file| require file }
Dir[File.dirname(__FILE__) + '/models/*.rb'].each { |file| require file } Dir[File.dirname(__FILE__) + '/models/*.rb'].each { |file| require file }
Dir[File.dirname(__FILE__) + '/presenters/*.rb'].each { |file| require file } Dir[File.dirname(__FILE__) + '/presenters/*.rb'].each { |file| require file }
Elasticsearch::Model.client = Elasticsearch::Client.new(host: CommentService.config[:elasticsearch_server], log: false)
# Ensure Elasticsearch index mappings exist.
Comment.put_search_index_mapping
CommentThread.put_search_index_mapping
# Comment out observers until notifications are actually set up properly.
#Dir[File.dirname(__FILE__) + '/models/observers/*.rb'].each {|file| require file}
#Mongoid.observers = PostReplyObserver, PostTopicObserver, AtUserObserver
#Mongoid.instantiate_observers
APIPREFIX = CommentService::API_PREFIX APIPREFIX = CommentService::API_PREFIX
DEFAULT_PAGE = 1 DEFAULT_PAGE = 1
......
...@@ -171,4 +171,17 @@ describe 'app' do ...@@ -171,4 +171,17 @@ describe 'app' do
expect(last_response.body).to include File.expand_path(__FILE__) expect(last_response.body).to include File.expand_path(__FILE__)
end end
end end
describe 'config' do
describe 'Elasticsearch client' do
subject { Elasticsearch::Model.client }
it 'has a host value set to that from application.yaml' do
expected = URI::parse(CommentService.config[:elasticsearch_server])
host = subject.transport.hosts[0]
host[:port] = host[:port].to_i
expect(URI::HTTP.build(host)).to eq expected
end
end
end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment