Class: TCB::EventBus::QueuePressureMonitor

Inherits:
Object
  • Object
show all
Defined in:
lib/tcb/event_bus/queue_pressure_monitor.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(high_water_mark:) ⇒ QueuePressureMonitor

Returns a new instance of QueuePressureMonitor.



12
13
14
15
# File 'lib/tcb/event_bus/queue_pressure_monitor.rb', line 12

def initialize(high_water_mark:)
  @high_water_mark = high_water_mark
  @emitted = false
end

Class Method Details

.for(max_queue_size:, high_water_mark:) ⇒ Object



6
7
8
9
10
# File 'lib/tcb/event_bus/queue_pressure_monitor.rb', line 6

def self.for(max_queue_size:, high_water_mark:)
  return new(high_water_mark:) if max_queue_size && high_water_mark

  NullQueuePressureMonitor.new
end

Instance Method Details

#check?(queue_size) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
23
24
25
26
# File 'lib/tcb/event_bus/queue_pressure_monitor.rb', line 17

def check?(queue_size)
  if queue_size >= @high_water_mark
    return false if @emitted
    @emitted = true
    true
  else
    @emitted = false
    false
  end
end