Module: Fluent::PluginHelper::Timer
- Includes:
- EventLoop
- Included in:
- ChildProcess, ServiceDiscovery, 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
-
#_timers ⇒ Object
readonly
stop : turn checker into false (callbacks not called anymore) shutdown : [-] close : [-] terminate: [-].
Attributes included from EventLoop
Attributes included from Thread
Instance Method Summary collapse
- #initialize ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #terminate ⇒ Object
-
#timer_execute(title, interval, repeat: true, &block) ⇒ Object
interval: integer/float, repeat: true/false.
- #timer_running? ⇒ Boolean
Methods included from EventLoop
#after_shutdown, #close, #event_loop_attach, #event_loop_detach, #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
#_timers ⇒ Object (readonly)
stop : turn checker into false (callbacks not called anymore) shutdown : [-] close : [-] terminate: [-]
30 31 32 |
# File 'lib/fluent/plugin_helper/timer.rb', line 30 def _timers @_timers end |
Instance Method Details
#initialize ⇒ Object
48 49 50 51 |
# File 'lib/fluent/plugin_helper/timer.rb', line 48 def initialize super @_timers ||= Set.new end |
#start ⇒ Object
53 54 55 56 |
# File 'lib/fluent/plugin_helper/timer.rb', line 53 def start super @_timer_running = true end |
#stop ⇒ Object
58 59 60 61 |
# File 'lib/fluent/plugin_helper/timer.rb', line 58 def stop super @_timer_running = false end |
#terminate ⇒ Object
63 64 65 66 |
# File 'lib/fluent/plugin_helper/timer.rb', line 63 def terminate super @_timers = nil end |
#timer_execute(title, interval, repeat: true, &block) ⇒ Object
interval: integer/float, repeat: true/false
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/fluent/plugin_helper/timer.rb', line 33 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 } detacher = ->(watcher){ event_loop_detach(watcher) } timer = TimerWatcher.new(title, interval, repeat, log, checker, detacher, &block) @_timers << title event_loop_attach(timer) timer end |
#timer_running? ⇒ Boolean
44 45 46 |
# File 'lib/fluent/plugin_helper/timer.rb', line 44 def timer_running? defined?(@_timer_running) && @_timer_running end |