Class: QueuePulse::Poller

Inherits:
Object
  • Object
show all
Defined in:
lib/queue_pulse/poller.rb

Overview

Optional background poller. Runs QueuePulse.check! every poll_interval seconds in a daemon thread. Opt-in (call QueuePulse.start_poller!) because most apps prefer scheduling CheckJob via Solid Queue recurring tasks.

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Poller

Returns a new instance of Poller.



8
9
10
11
12
# File 'lib/queue_pulse/poller.rb', line 8

def initialize(config)
  @config = config
  @thread = nil
  @running = false
end

Instance Method Details

#running?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/queue_pulse/poller.rb', line 37

def running?
  @running
end

#startObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/queue_pulse/poller.rb', line 14

def start
  return self if @running

  @running = true
  @thread = Thread.new do
    Thread.current.name = "queue_pulse-poller"
    loop do
      break unless @running

      QueuePulse.check!
      sleep(@config.poll_interval)
    end
  end
  @config.logger.info("[QueuePulse] poller started (every #{@config.poll_interval}s)")
  self
end

#stopObject



31
32
33
34
35
# File 'lib/queue_pulse/poller.rb', line 31

def stop
  @running = false
  @thread&.wakeup
  @thread = nil
end