Class: LitmusPaper::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/litmus_paper/service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, dependencies = [], checks = []) ⇒ Service

Returns a new instance of Service.



5
6
7
8
9
# File 'lib/litmus_paper/service.rb', line 5

def initialize(name, dependencies = [], checks = [])
  @name = name
  @dependencies = dependencies
  @checks = checks
end

Instance Attribute Details

#checksObject (readonly)

Returns the value of attribute checks.



3
4
5
# File 'lib/litmus_paper/service.rb', line 3

def checks
  @checks
end

Instance Method Details

#_determine_forced_healthObject



41
42
43
44
45
# File 'lib/litmus_paper/service.rb', line 41

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

#_health_filesObject



37
38
39
# File 'lib/litmus_paper/service.rb', line 37

def _health_files
  StatusFile.priority_check_order_for_service(@name)
end

#current_healthObject



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/litmus_paper/service.rb', line 11

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

#depends(dependency_class, *args) ⇒ Object



33
34
35
# File 'lib/litmus_paper/service.rb', line 33

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

#measure_health(metric_class, options) ⇒ Object



25
26
27
# File 'lib/litmus_paper/service.rb', line 25

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

#measure_health_with_args(metric_class, *args) ⇒ Object



29
30
31
# File 'lib/litmus_paper/service.rb', line 29

def measure_health_with_args(metric_class, *args)
  @checks << metric_class.new(*args)
end