Class: Fluent::PluginHelper::Timer::TimerWatcher

Inherits:
Coolio::TimerWatcher
  • Object
show all
Defined in:
lib/fluent/plugin_helper/timer.rb

Instance Method Summary collapse

Constructor Details

#initialize(title, interval, repeat, log, checker, detacher, &callback) ⇒ TimerWatcher

Returns a new instance of TimerWatcher.



69
70
71
72
73
74
75
76
77
# File 'lib/fluent/plugin_helper/timer.rb', line 69

def initialize(title, interval, repeat, log, checker, detacher, &callback)
  @title = title
  @callback = callback
  @repeat = repeat
  @log = log
  @checker = checker
  @detacher = detacher
  super(interval, repeat)
end

Instance Method Details

#on_timerObject



79
80
81
82
83
84
85
86
87
88
# File 'lib/fluent/plugin_helper/timer.rb', line 79

def on_timer
  @callback.call if @checker.call
rescue => e
  @log.error "Unexpected error raised. Stopping the timer.", title: @title, error: e
  @log.error_backtrace
  detach
  @log.error "Timer detached.", title: @title
ensure
  @detacher.call(self) unless @repeat
end