Module: Fluent::PluginHelper::Timer

Includes:
EventLoop
Included in:
ChildProcess, Storage
Defined in:
lib/fluent/plugin_helper/timer.rb

Defined Under Namespace

Classes: TimerWatcher

Constant Summary

Constants included from EventLoop

EventLoop::EVENT_LOOP_RUN_DEFAULT_TIMEOUT

Constants included from Thread

Fluent::PluginHelper::Thread::THREAD_DEFAULT_WAIT_SECONDS

Instance Attribute Summary collapse

Attributes included from EventLoop

#_event_loop

Attributes included from Thread

#_threads

Instance Method Summary collapse

Methods included from EventLoop

#close, #event_loop_attach, #event_loop_running?, #event_loop_wait_until_start, #event_loop_wait_until_stop, #shutdown

Methods included from Thread

#after_shutdown, #close, #thread_create, #thread_current_running?, #thread_exist?, #thread_running?, #thread_started?, #thread_wait_until_start, #thread_wait_until_stop

Instance Attribute Details

#_timersObject (readonly)

stop : turn checker into false (callbacks not called anymore) shutdown : [-] close : [-] terminate: [-]



29
30
31
# File 'lib/fluent/plugin_helper/timer.rb', line 29

def _timers
  @_timers
end

Instance Method Details

#initializeObject



45
46
47
48
# File 'lib/fluent/plugin_helper/timer.rb', line 45

def initialize
  super
  @_timers = []
end

#startObject



50
51
52
53
# File 'lib/fluent/plugin_helper/timer.rb', line 50

def start
  super
  @_timer_running = true
end

#stopObject



55
56
57
58
# File 'lib/fluent/plugin_helper/timer.rb', line 55

def stop
  super
  @_timer_running = false
end

#terminateObject



60
61
62
63
# File 'lib/fluent/plugin_helper/timer.rb', line 60

def terminate
  super
  @_timers = []
end

#timer_execute(title, interval, repeat: true, &block) ⇒ Object

interval: integer/float, repeat: true/false

Raises:

  • (ArgumentError)


32
33
34
35
36
37
38
39
# File 'lib/fluent/plugin_helper/timer.rb', line 32

def timer_execute(title, interval, repeat: true, &block)
  raise ArgumentError, "BUG: title must be a symbol" unless title.is_a? Symbol
  raise ArgumentError, "BUG: block not specified for callback" unless block_given?
  checker = ->(){ @_timer_running }
  timer = TimerWatcher.new(title, interval, repeat, log, checker, &block)
  @_timers << title
  event_loop_attach(timer)
end

#timer_running?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/fluent/plugin_helper/timer.rb', line 41

def timer_running?
  defined?(@_timer_running) && @_timer_running
end