Class: Kurchatov::Monitor

Inherits:
Object
  • Object
show all
Defined in:
lib/kurchatov/monitor.rb

Defined Under Namespace

Classes: Task

Constant Summary collapse

CHECK_ALIVE_TIMEOUT =
5

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMonitor

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

#tasksObject

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

#inspectObject



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