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
- #start! ⇒ 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 16 |
# 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 @last_error_count = 0 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
22 23 24 |
# File 'lib/kurchatov/monitor.rb', line 22 def config @plugin.plugin_config end |
#died? ⇒ Boolean
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/kurchatov/monitor.rb', line 34 def died? if @thread.alive? @last_error_count = 0 return false end # 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_count += 1 @last_error = desc @last_error_at = Time.now Log.error(desc) if @plugin.ignore_errors == false || (@plugin.ignore_errors.class == 'Fixnum' && @plugin.ignore_errors > @plugin.last_error_count) event(:service => "plugin #{@plugin.name} errors", :desc => desc, :state => 'critical') end end true end |
#name ⇒ Object
18 19 20 |
# File 'lib/kurchatov/monitor.rb', line 18 def name @plugin.name end |
#start! ⇒ Object
57 58 59 |
# File 'lib/kurchatov/monitor.rb', line 57 def start! @thread = Thread.new { @plugin.start! } end |
#stop! ⇒ Object
26 27 28 |
# File 'lib/kurchatov/monitor.rb', line 26 def stop! Thread.kill(@thread) end |
#stopped? ⇒ Boolean
30 31 32 |
# File 'lib/kurchatov/monitor.rb', line 30 def stopped? @plugin.stopped? end |