Sha256: 6af7507ddb753be97d7f79aa5d5387010d36fceb0c23e88f80280757d5e22070

Contents?: true

Size: 1.31 KB

Versions: 4

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

require_relative "config"
require_relative "logging_helpers"
require_relative "signal_manager"

require "frankenstein/ruby_gc_metrics"
require "frankenstein/ruby_vm_metrics"
require "frankenstein/process_metrics"
require "frankenstein/server"
require "prometheus/client/registry"
require "sigdump"
require "ultravisor"

module ServiceSkeleton
  class Runner
    include ServiceSkeleton::LoggingHelpers

    def initialize(klass, env)
      @config = (klass.config_class || ServiceSkeleton::Config).new(env, klass.service_name, klass.registered_variables)
      @logger = @config.logger

      @metrics_registry = Prometheus::Client::Registry.new

      @ultravisor = ServiceSkeleton.generate(
        config: @config,
        metrics_registry: @metrics_registry,
        service_metrics: klass.registered_metrics,
        service_signal_handlers: { klass.service_name.to_sym => klass.registered_signal_handlers }
      )

      klass.register_ultravisor_children(@ultravisor, config: @config, metrics_registry: @metrics_registry)
    end

    def run
      logger.info(logloc) { "Starting service #{@config.service_name}" }
      logger.info(logloc) { (["Environment:"] + @config.env.map { |k, v| "#{k}=#{v.inspect}" }).join("\n  ") }

      @ultravisor.run
    end

    private

    attr_reader :logger
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
service_skeleton-1.0.2 lib/service_skeleton/runner.rb
service_skeleton-1.0.1 lib/service_skeleton/runner.rb
service_skeleton-0.0.0.49.g47046b9 lib/service_skeleton/runner.rb
service_skeleton-0.0.0.48.g4a40599 lib/service_skeleton/runner.rb