Class: ForgeOpsTracker::DeliveryQueue

Inherits:
Object
  • Object
show all
Defined in:
lib/forge_ops_tracker/delivery_queue.rb

Overview

A small in-process background thread + bounded queue, so delivery never blocks the request that raised the error and never depends on the host app having any particular job backend configured. The worker thread is started lazily on first push (not at load time), so it's created fresh in each forked Puma/Passenger worker process rather than being carried across a fork, which would leave it dead in the child.

Instance Method Summary collapse

Constructor Details

#initialize(configuration, client: Client.new(configuration)) ⇒ DeliveryQueue

Returns a new instance of DeliveryQueue.



11
12
13
14
15
16
17
# File 'lib/forge_ops_tracker/delivery_queue.rb', line 11

def initialize(configuration, client: Client.new(configuration))
  @configuration = configuration
  @client = client
  @queue = SizedQueue.new(configuration.queue_size)
  @mutex = Mutex.new
  @thread = nil
end

Instance Method Details

#push(payload) ⇒ Object

Enqueues a payload, dropping it silently (never blocking the caller) if the queue is already full -- a burst of exceptions must never apply backpressure to the host app.



22
23
24
25
26
27
28
29
# File 'lib/forge_ops_tracker/delivery_queue.rb', line 22

def push(payload)
  ensure_worker_started
  @queue.push(payload, true)
  true
rescue ThreadError
  log { "delivery queue full, dropping event" }
  false
end