Module: D13n::Service::Start

Included in:
D13n::Service
Defined in:
lib/d13n/service/start.rb

Instance Method Summary collapse

Instance Method Details

#config_server_raise_on_failure?Boolean



63
64
65
# File 'lib/d13n/service/start.rb', line 63

def config_server_raise_on_failure?
  D13n.config[:'config_server.raise_on_failure'] == true || D13n.config[:'config_server.raise_on_failure'] == 'true'
end

#log_environmentObject



25
26
27
# File 'lib/d13n/service/start.rb', line 25

def log_environment
  D13n.logger.info "Environment: #{D13n.service.instance.env}"
end

#log_service_nameObject



29
30
31
# File 'lib/d13n/service/start.rb', line 29

def log_service_name
  D13n.logger.info "Service: #{D13n.config.app_name}"
end

#log_startupObject



20
21
22
23
# File 'lib/d13n/service/start.rb', line 20

def log_startup
  log_environment
  log_service_name
end

#log_version_and_pidObject



33
34
35
# File 'lib/d13n/service/start.rb', line 33

def log_version_and_pid
  D13n.logger.debug "#{D13n.config.app_name} Service #{D13n.service.app_class::VERSION}(D13n:#{D13n::VERSION::STRING}) Initialized: pid = #{$$}"
end

#query_server_for_configurationObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/d13n/service/start.rb', line 37

def query_server_for_configuration
  begin
    #
    # TODO: Config Kit may enhance configurator
    #
    ConfigKit.config.url = D13n.config[:ck_url] || D13n.config[:'service.config_kit.url']
    config_data = ConfigKit::Manager.get(D13n.config.app_name)
  rescue ConfigKit::Client::ConfigKitReadError => e
    D13n.logger.error "Config Kit reads server error. #{e.message}"
    raise ServiceStartError.new(e.message) if config_server_raise_on_failure?
  rescue Exception => e
    D13n.logger.error "Unknown Config Kit error. #{e.message}"
    D13n.logger.debug e
    raise ServiceStartError.new(e.message) if config_server_raise_on_failure?
  end
  #
  # TODO: Empty to raise exception
  #
  return if config_data.nil? || config_data.empty?

  D13n.logger.debug "Server provided config: #{config_data.inspect}"

  server_config = D13n::Configuration::ServerSource.build(config_data)
  D13n.config.replace_or_add_config(server_config)
end

#start_api_serviceObject



15
16
17
18
# File 'lib/d13n/service/start.rb', line 15

def start_api_service
  @started = true
  Object.const_get("#{D13n.application.name}::Api::Service").run!(@service_conf)
end

#start_metric_managerObject



6
7
8
9
10
11
12
13
# File 'lib/d13n/service/start.rb', line 6

def start_metric_manager
  begin
    channel = determine_metric_channel
    Metric::Manager.start(channel)
  rescue Exception => e
    D13n.logger.error "Unknown Instrument Manager error. #{e.message}"
  end
end