Class: Kurchatov::Monitor
- Inherits:
-
Object
- Object
- Kurchatov::Monitor
- Defined in:
- lib/kurchatov/monitor.rb
Defined Under Namespace
Classes: Task
Constant Summary collapse
- CHECK_ALIVE_TIMEOUT =
5
Instance Attribute Summary collapse
-
#tasks ⇒ Object
Returns the value of attribute tasks.
Instance Method Summary collapse
- #<<(plugin) ⇒ Object
-
#initialize ⇒ Monitor
constructor
A new instance of Monitor.
- #inspect ⇒ Object
- #start! ⇒ Object
Constructor Details
#initialize ⇒ Monitor
Returns a new instance of Monitor.
66 67 68 |
# File 'lib/kurchatov/monitor.rb', line 66 def initialize @tasks = Array.new end |
Instance Attribute Details
#tasks ⇒ Object
Returns the value of attribute tasks.
63 64 65 |
# File 'lib/kurchatov/monitor.rb', line 63 def tasks @tasks end |
Instance Method Details
#<<(plugin) ⇒ Object
70 71 72 73 |
# File 'lib/kurchatov/monitor.rb', line 70 def <<(plugin) Log.debug("Add new plugin: #{plugin.inspect}") tasks << Task.new(plugin) end |
#inspect ⇒ Object
89 90 91 92 93 94 95 96 97 |
# File 'lib/kurchatov/monitor.rb', line 89 def inspect tasks.map do |t| { "name" => t.name, "config" => t.config, "errors" => {"count" => t.count_errors, "last" => t.last_error, "time" => t.last_error_at} } end end |
#start! ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/kurchatov/monitor.rb', line 75 def start! loop do tasks.each do |task| task.start! if task.died? if task.stopped? task.stop! tasks.delete(task) end end Log.debug("Check alive plugins [#{tasks.count}]") sleep CHECK_ALIVE_TIMEOUT end end |