Class: Boatload::Timer

Inherits:
Object
  • Object
show all
Defined in:
lib/boatload/timer.rb

Overview

A timer that will periodically tell the Worker to process messages.

Instance Method Summary collapse

Constructor Details

#initialize(queue:, delivery_interval:, logger:) ⇒ Timer

Returns a new instance of Timer.



6
7
8
9
10
# File 'lib/boatload/timer.rb', line 6

def initialize(queue:, delivery_interval:, logger:)
  @logger = logger
  @queue = queue
  @delivery_interval = delivery_interval
end

Instance Method Details

#runObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/boatload/timer.rb', line 12

def run
  Thread.stop if @delivery_interval.zero?
  @logger.info 'Starting Timer...'

  loop do
    sleep @delivery_interval
    @queue.push [:process, nil]
  end
rescue StandardError => e
  @logger.error "Timer thread encountered an unexpected error:\n#{e.full_message}"
end