Class: Igniter::Store::ChangefeedBuffer::DiagnosticRing
- Inherits:
-
Object
- Object
- Igniter::Store::ChangefeedBuffer::DiagnosticRing
- Defined in:
- lib/igniter/store/changefeed_buffer.rb
Overview
Bounded ring buffer for structured diagnostic entries. All push/snapshot operations are thread-safe. Oldest entries are evicted when max_size is exceeded; dropped_diagnostics_total counts evictions.
Instance Method Summary collapse
-
#initialize(max_size) ⇒ DiagnosticRing
constructor
A new instance of DiagnosticRing.
- #push(entry) ⇒ Object
- #snapshot ⇒ Object
Constructor Details
#initialize(max_size) ⇒ DiagnosticRing
Returns a new instance of DiagnosticRing.
134 135 136 137 138 139 140 |
# File 'lib/igniter/store/changefeed_buffer.rb', line 134 def initialize(max_size) @max_size = max_size @entries = [] @mu = Mutex.new @total = 0 @dropped = 0 end |
Instance Method Details
#push(entry) ⇒ Object
142 143 144 145 146 147 148 149 150 151 |
# File 'lib/igniter/store/changefeed_buffer.rb', line 142 def push(entry) @mu.synchronize do @total += 1 if @entries.size >= @max_size @entries.shift @dropped += 1 end @entries << entry end end |
#snapshot ⇒ Object
153 154 155 156 157 158 159 160 161 |
# File 'lib/igniter/store/changefeed_buffer.rb', line 153 def snapshot @mu.synchronize do { recent: @entries.dup, recent_count: @total, dropped_diagnostics_total: @dropped } end end |