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, EventLoop::EVENT_LOOP_SHUTDOWN_TIMEOUT

Constants included from Thread

Fluent::PluginHelper::Thread::THREAD_DEFAULT_WAIT_SECONDS, Fluent::PluginHelper::Thread::THREAD_SHUTDOWN_HARD_TIMEOUT_IN_TESTS

Instance Attribute Summary collapse

Attributes included from EventLoop

#_event_loop

Attributes included from Thread

#_threads

Instance Method Summary collapse

Methods included from EventLoop

#after_shutdown, #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



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

def initialize
  super
  @_timers = []
end

#startObject



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

def start
  super
  @_timer_running = true
end

#stopObject



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

def stop
  super
  @_timer_running = false
end

#terminateObject



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

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
40
# 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)
  timer
end

#timer_running?Boolean

Returns:

  • (Boolean)


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

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