lib/service_skeleton.rb in service_skeleton-0.0.0.3.g1269800 vs lib/service_skeleton.rb in service_skeleton-0.0.0.3.g1269800.1.gaaa2fa1

- old
+ new

@@ -61,15 +61,17 @@ @thread = nil end def stop(force = false) if force + #:nocov: @op_mutex.synchronize do if @thread @thread.raise(ServiceSkeleton::Terminate) end end + #:nocov: else shutdown end if @metrics_server @@ -97,17 +99,19 @@ def run raise ServiceSkeleton::Error::InheritanceContractError, "ServiceSkeleton#run method not overridden" end def shutdown + #:nocov: @op_mutex.synchronize do if @thread @thread.raise(ServiceSkeleton::Terminate) @thread.join @thread = nil end end + #:nocov: end def setup_metrics @metrics = Prometheus::Client::Registry.new @@ -133,11 +137,11 @@ @metrics_server.run end end def setup_signals - @signal_handler = ServiceSkeleton::SignalHandler.new(logger: logger, service: self, signal_counter: metrics.counter(:"#{service_name}_signals_handled_total", "How many of each type of signal have been handled")) + @signal_handler = ServiceSkeleton::SignalHandler.new(logger: logger, service: self, signal_counter: metrics.counter(:"#{self.service_name}_signals_handled_total", "How many of each type of signal have been handled")) @signal_handler.hook_signal("USR1") do logger.level -= 1 unless logger.level == Logger::DEBUG logger.info($0) { "Received SIGUSR1; log level is now #{Logger::SEV_LABEL[logger.level]}." } end @@ -171,18 +175,20 @@ @signal_handler.start! end @registered_variables = [ ServiceSkeleton::ConfigVariable.new(:SERVICE_SKELETON_LOG_LEVEL) { "INFO" }, + ServiceSkeleton::ConfigVariable.new(:SERVICE_SKELETON_LOGSTASH_SERVER) { "" }, ServiceSkeleton::ConfigVariable.new(:SERVICE_SKELETON_LOG_ENABLE_TIMESTAMPS) { false }, ServiceSkeleton::ConfigVariable.new(:SERVICE_SKELETON_LOG_FILE) { nil }, ServiceSkeleton::ConfigVariable.new(:SERVICE_SKELETON_LOG_MAX_FILE_SIZE) { 1048576 }, ServiceSkeleton::ConfigVariable.new(:SERVICE_SKELETON_LOG_MAX_FILES) { 3 }, ServiceSkeleton::ConfigVariable.new(:SERVICE_SKELETON_METRICS_PORT) { nil }, ] def self.inherited(subclass) subclass.string(:"#{subclass.service_name.upcase}_LOG_LEVEL", default: "INFO") + subclass.string(:"#{subclass.service_name.upcase}_LOGSTASH_SERVER", default: "") subclass.boolean(:"#{subclass.service_name.upcase}_LOG_ENABLE_TIMESTAMPS", default: false) subclass.string(:"#{subclass.service_name.upcase}_LOG_FILE", default: nil) subclass.integer(:"#{subclass.service_name.upcase}_LOG_MAX_FILE_SIZE", default: 1048576, range: 0..Float::INFINITY) subclass.integer(:"#{subclass.service_name.upcase}_LOG_MAX_FILES", default: 3, range: 1..Float::INFINITY) subclass.integer(:"#{subclass.service_name.upcase}_METRICS_PORT", default: nil, range: 1..65535)