Class: IPVSLitmus::Service
- Inherits:
-
Object
- Object
- IPVSLitmus::Service
- Defined in:
- lib/ipvs_litmus/service.rb
Instance Method Summary collapse
- #_determine_forced_health ⇒ Object
- #_health_files ⇒ Object
- #current_health ⇒ Object
- #depends(dependency_class, *args) ⇒ Object
-
#initialize(name, dependencies = [], checks = []) ⇒ Service
constructor
A new instance of Service.
- #measure_health(metric_class, options) ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(name, dependencies = [], checks = []) ⇒ Service
Returns a new instance of Service.
3 4 5 6 7 |
# File 'lib/ipvs_litmus/service.rb', line 3 def initialize(name, dependencies = [], checks = []) @name = name @dependencies = dependencies @checks = checks end |
Instance Method Details
#_determine_forced_health ⇒ Object
45 46 47 48 49 |
# File 'lib/ipvs_litmus/service.rb', line 45 def _determine_forced_health _health_files.map do |health, status_file| ForcedHealth.new(health, status_file.content) if status_file.exists? end.compact.first end |
#_health_files ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/ipvs_litmus/service.rb', line 36 def _health_files @health_files ||= [ [0, IPVSLitmus::StatusFile.new('down', @name)], [100, IPVSLitmus::StatusFile.new('up', @name)], [0, IPVSLitmus::StatusFile.new('global_down')], [100, IPVSLitmus::StatusFile.new('global_up')] ] end |
#current_health ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/ipvs_litmus/service.rb', line 13 def current_health forced_health = _determine_forced_health return forced_health unless forced_health.nil? health = IPVSLitmus::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
32 33 34 |
# File 'lib/ipvs_litmus/service.rb', line 32 def depends(dependency_class, *args) @dependencies << dependency_class.new(*args) end |
#measure_health(metric_class, options) ⇒ Object
28 29 30 |
# File 'lib/ipvs_litmus/service.rb', line 28 def measure_health(metric_class, ) @checks << metric_class.new([:weight]) end |
#success? ⇒ Boolean
9 10 11 |
# File 'lib/ipvs_litmus/service.rb', line 9 def success? health > 0 end |