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.



12
13
14
15
# File 'lib/say_when/poller/concurrent_poller.rb', line 12

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

Instance Method Details

#startObject



17
18
19
20
21
# File 'lib/say_when/poller/concurrent_poller.rb', line 17

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

#stopObject



23
24
25
26
27
28
# File 'lib/say_when/poller/concurrent_poller.rb', line 23

def stop
  if @tick_timer
    @tick_timer.shutdown
    @tick_timer = nil
  end
end