Sha256: b4da97b4d7c1a24b1511c3587ba208faf25b77f7d4e675b0d13b1a3d3a38b046

Contents?: true

Size: 1.37 KB

Versions: 8

Compression:

Stored size: 1.37 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_relative "../../ultravisor/lib/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
      @config.pre_run_logger.info(logloc) { "Starting service #{@config.service_name}" }
      @config.pre_run_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

8 entries across 8 versions & 1 rubygems

Version Path
service_skeleton-2.2.0 lib/service_skeleton/runner.rb
service_skeleton-2.1.0 lib/service_skeleton/runner.rb
service_skeleton-1.0.5 lib/service_skeleton/runner.rb
service_skeleton-2.0.2 lib/service_skeleton/runner.rb
service_skeleton-2.0.1 lib/service_skeleton/runner.rb
service_skeleton-2.0.0 lib/service_skeleton/runner.rb
service_skeleton-1.0.4 lib/service_skeleton/runner.rb
service_skeleton-0.0.0.1.ENOTAG lib/service_skeleton/runner.rb