Class: SayWhen::Poller::ConcurrentPoller

Inherits:
Object
  • Object
show all
Includes:
BasePoller
Defined in:
lib/say_when/poller/concurrent_poller.rb

Instance Method Summary collapse

Methods included from BasePoller

#acquire, #error_tick_length, included, #job_error, #logger, #process, #process_jobs, #processor, #release, #reset_acquired, #reset_acquired_length, #storage, #tick, #tick_length

Constructor Details

#initialize(tick = nil) ⇒ ConcurrentPoller

Returns a new instance of ConcurrentPoller.



10
11
12
# File 'lib/say_when/poller/concurrent_poller.rb', line 10

def initialize(tick = nil)
  @tick_length = tick.to_i if tick
end

Instance Method Details

#startObject



14
15
16
17
18
# File 'lib/say_when/poller/concurrent_poller.rb', line 14

def start
  @tick_timer ||= Concurrent::TimerTask.new(execution_interval: tick_length) do
    process_jobs
  end.tap(&:execute)
end

#stopObject



20
21
22
23
24
25
# File 'lib/say_when/poller/concurrent_poller.rb', line 20

def stop
  return unless @tick_timer

  @tick_timer.shutdown
  @tick_timer = nil
end