Class: LogStash::ThreadWatchdog
- Inherits:
-
Object
- Object
- LogStash::ThreadWatchdog
- Defined in:
- lib/logstash/threadwatchdog.rb
Defined Under Namespace
Classes: TimeoutError
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#threads ⇒ Object
Returns the value of attribute threads.
Instance Method Summary collapse
-
#initialize(threads, watchdog_timeout = 10) ⇒ ThreadWatchdog
constructor
A new instance of ThreadWatchdog.
- #watch ⇒ Object
Constructor Details
#initialize(threads, watchdog_timeout = 10) ⇒ ThreadWatchdog
Returns a new instance of ThreadWatchdog.
12 13 14 15 |
# File 'lib/logstash/threadwatchdog.rb', line 12 def initialize(threads, watchdog_timeout=10) @threads = threads @watchdog_timeout = watchdog_timeout end |
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
6 7 8 |
# File 'lib/logstash/threadwatchdog.rb', line 6 def logger @logger end |
#threads ⇒ Object
Returns the value of attribute threads.
7 8 9 |
# File 'lib/logstash/threadwatchdog.rb', line 7 def threads @threads end |
Instance Method Details
#watch ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/logstash/threadwatchdog.rb', line 18 def watch while sleep(1) cutoff = Time.now - @watchdog_timeout @threads.each do |t| watchdog = t[:watchdog] if watchdog and watchdog <= cutoff age = Time.now - watchdog @logger.fatal("thread watchdog timeout", :thread => t, :backtrace => t.backtrace, :thread_watchdog => watchdog, :age => age, :cutoff => @watchdog_timeout, :state => t[:watchdog_state]) raise TimeoutError, "watchdog timeout" end end end end |