Sha256: 0954c3a42e79442d93600dc73dd1efad76ca7059d98b665569548d1ca3f0ceaa

Contents?: true

Size: 1.51 KB

Versions: 11

Compression:

Stored size: 1.51 KB

Contents

# frozen_string_literal: true

module Orchestration
  module Services
    module HealthcheckBase
      attr_reader :configuration

      def self.included(base)
        base.extend(ClassMethods)
      end

      module ClassMethods
        def start(env = nil, terminal = nil, options = {})
          load_dependencies
          exit_on_error = options.fetch(:exit_on_error, true)
          options.delete(:exit_on_error)
          env ||= Environment.new
          terminal ||= Terminal.new(env.settings)
          name = options.delete(:service_name)
          check = ServiceCheck.new(new(env, name, options), terminal, options)

          exit 1 if !check.run && exit_on_error
        end

        def dependencies(*args)
          @dependencies = args
        end

        private

        def load_dependencies
          return if @dependencies.nil?

          @dependencies.map { |dependency| require dependency }
        end
      end

      def initialize(env, service_name = nil, options = {})
        @options = options
        @configuration = configuration_class.new(env, service_name, options)
      end

      def service_name
        @configuration.service_name
      end

      private

      def configuration_class
        # Find the relevant `Configuration` class for whatever `Healthcheck`
        # class we happen to be included in.
        instance_eval(self.class.name.rpartition('::').first)
          .const_get(:Configuration)
      end

      def devnull
        File.open(File::NULL, 'w')
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
orchestration-0.4.20 lib/orchestration/services/mixins/healthcheck_base.rb
orchestration-0.4.19 lib/orchestration/services/mixins/healthcheck_base.rb
orchestration-0.4.18 lib/orchestration/services/mixins/healthcheck_base.rb
orchestration-0.4.17 lib/orchestration/services/mixins/healthcheck_base.rb
orchestration-0.4.16 lib/orchestration/services/mixins/healthcheck_base.rb
orchestration-0.4.15 lib/orchestration/services/mixins/healthcheck_base.rb
orchestration-0.4.14 lib/orchestration/services/mixins/healthcheck_base.rb
orchestration-0.4.13 lib/orchestration/services/mixins/healthcheck_base.rb
orchestration-0.4.12 lib/orchestration/services/mixins/healthcheck_base.rb
orchestration-0.4.10 lib/orchestration/services/mixins/healthcheck_base.rb
orchestration-0.4.9 lib/orchestration/services/mixins/healthcheck_base.rb