Class: Kurchatov::Monitor::Task
- Inherits:
-
Object
- Object
- Kurchatov::Monitor::Task
- Includes:
- Kurchatov::Mixin::Event
- Defined in:
- lib/kurchatov/monitor.rb
Constant Summary
Constants included from Kurchatov::Mixin::Event
Kurchatov::Mixin::Event::EVENT_FIELDS
Instance Attribute Summary collapse
-
#count_errors ⇒ Object
readonly
Returns the value of attribute count_errors.
-
#instance ⇒ Object
Returns the value of attribute instance.
-
#last_error ⇒ Object
readonly
Returns the value of attribute last_error.
-
#last_error_at ⇒ Object
readonly
Returns the value of attribute last_error_at.
-
#thread ⇒ Object
Returns the value of attribute thread.
Instance Method Summary collapse
- #config ⇒ Object
- #died? ⇒ Boolean
-
#initialize(plugin) ⇒ Task
constructor
A new instance of Task.
- #name ⇒ Object
- #stop! ⇒ Object
- #stopped? ⇒ Boolean
Methods included from Kurchatov::Mixin::Event
Methods included from Kurchatov::Mixin::Queue
Constructor Details
#initialize(plugin) ⇒ Task
Returns a new instance of Task.
9 10 11 12 13 14 15 |
# File 'lib/kurchatov/monitor.rb', line 9 def initialize(plugin) @plugin = plugin @thread = Thread.new { @plugin.start! } @count_errors = 0 @last_error = nil @last_error_at = nil end |
Instance Attribute Details
#count_errors ⇒ Object (readonly)
Returns the value of attribute count_errors.
7 8 9 |
# File 'lib/kurchatov/monitor.rb', line 7 def count_errors @count_errors end |
#instance ⇒ Object
Returns the value of attribute instance.
6 7 8 |
# File 'lib/kurchatov/monitor.rb', line 6 def instance @instance end |
#last_error ⇒ Object (readonly)
Returns the value of attribute last_error.
7 8 9 |
# File 'lib/kurchatov/monitor.rb', line 7 def last_error @last_error end |
#last_error_at ⇒ Object (readonly)
Returns the value of attribute last_error_at.
7 8 9 |
# File 'lib/kurchatov/monitor.rb', line 7 def last_error_at @last_error_at end |
#thread ⇒ Object
Returns the value of attribute thread.
6 7 8 |
# File 'lib/kurchatov/monitor.rb', line 6 def thread @thread end |
Instance Method Details
#config ⇒ Object
21 22 23 |
# File 'lib/kurchatov/monitor.rb', line 21 def config @plugin.plugin_config end |
#died? ⇒ Boolean
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/kurchatov/monitor.rb', line 33 def died? return false if @thread.alive? # thread died, join and extract error begin @thread.join # call error rescue => e desc = "Plugin '#{@plugin.name}' died. #{e.class}: #{e}\n." + "Trace: #{e.backtrace.join("\n")}" @count_errors += 1 @last_error = desc @last_error_at = Time.now Log.error(desc) unless @plugin.ignore_errors event(:service => "plugin #{@plugin.name} errors", :desc => desc, :state => 'critical') end end @thread = Thread.new { @plugin.start! } true end |
#name ⇒ Object
17 18 19 |
# File 'lib/kurchatov/monitor.rb', line 17 def name @plugin.name end |
#stop! ⇒ Object
25 26 27 |
# File 'lib/kurchatov/monitor.rb', line 25 def stop! Thread.kill(@thread) end |
#stopped? ⇒ Boolean
29 30 31 |
# File 'lib/kurchatov/monitor.rb', line 29 def stopped? @plugin.stopped? end |