Sha256: 0422959a84d751bc890035b8e85e055f974bb27e34d1374d1ecb630b7a44d630

Contents?: true

Size: 1020 Bytes

Versions: 16

Compression:

Stored size: 1020 Bytes

Contents

module LitmusPaper
  class Service
    def initialize(name, dependencies = [], checks = [])
      @name = name
      @dependencies = dependencies
      @checks = checks
    end

    def current_health
      forced_health = _determine_forced_health
      return forced_health unless forced_health.nil?

      health = LitmusPaper::Health.new
      @dependencies.each do |dependency|
        health.ensure(dependency)
      end

      @checks.each do |check|
        health.perform(check)
      end
      health
    end

    def measure_health(metric_class, options)
      @checks << metric_class.new(options[:weight])
    end

    def depends(dependency_class, *args)
      @dependencies << dependency_class.new(*args)
    end

    def _health_files
      StatusFile.priority_check_order_for_service(@name)
    end

    def _determine_forced_health
      _health_files.map do |status_file|
        ForcedHealth.new(status_file.health, status_file.content) if status_file.exists?
      end.compact.first
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
litmus_paper-0.8.2 lib/litmus_paper/service.rb
litmus_paper-0.8.1 lib/litmus_paper/service.rb
litmus_paper-0.8.0 lib/litmus_paper/service.rb
litmus_paper-0.7.9 lib/litmus_paper/service.rb
litmus_paper-0.7.5 lib/litmus_paper/service.rb
litmus_paper-0.7.4 lib/litmus_paper/service.rb
litmus_paper-0.7.3 lib/litmus_paper/service.rb
litmus_paper-0.7.2 lib/litmus_paper/service.rb
litmus_paper-0.7.1 lib/litmus_paper/service.rb
litmus_paper-0.7.0 lib/litmus_paper/service.rb
litmus_paper-0.6.3 lib/litmus_paper/service.rb
litmus_paper-0.6.2 lib/litmus_paper/service.rb
litmus_paper-0.6.1 lib/litmus_paper/service.rb
litmus_paper-0.6.0 lib/litmus_paper/service.rb
litmus_paper-0.5.0 lib/litmus_paper/service.rb
litmus_paper-0.4.0 lib/litmus_paper/service.rb