Sha256: 84d75a5f8d30642e7c25e140f6a9b96b2d5d319fb7debe8b783999713a17a31f

Contents?: true

Size: 1006 Bytes

Versions: 10

Compression:

Stored size: 1006 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

      health = forced_health ? forced_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|
        LitmusPaper::Health.new(status_file.forced, status_file.content) if status_file.exists?
      end.compact.first
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
litmus_paper-0.9.2 lib/litmus_paper/service.rb
litmus_paper-0.9.1 lib/litmus_paper/service.rb
litmus_paper-0.9.0 lib/litmus_paper/service.rb
litmus_paper-0.8.9 lib/litmus_paper/service.rb
litmus_paper-0.8.8 lib/litmus_paper/service.rb
litmus_paper-0.8.7 lib/litmus_paper/service.rb
litmus_paper-0.8.6 lib/litmus_paper/service.rb
litmus_paper-0.8.5 lib/litmus_paper/service.rb
litmus_paper-0.8.4 lib/litmus_paper/service.rb
litmus_paper-0.8.3 lib/litmus_paper/service.rb