Class: Langfuse::PendingScoreQueue Private
- Inherits:
-
Object
- Object
- Langfuse::PendingScoreQueue
- Defined in:
- lib/langfuse/pending_score_queue.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Thread-safe bounded queue that keeps scores until delivery succeeds.
Instance Attribute Summary collapse
-
#capacity ⇒ Integer
readonly
private
Maximum number of pending scores.
Instance Method Summary collapse
-
#empty? ⇒ Boolean
private
True when no events are pending.
-
#first(limit) ⇒ Array<Hash>
private
Return up to limit events from the front without removing them.
-
#initialize(capacity:) ⇒ PendingScoreQueue
constructor
private
A new instance of PendingScoreQueue.
-
#push(event) ⇒ Boolean
private
Add an event without waiting for queue capacity.
-
#remove_prefix(count) ⇒ void
private
Remove a delivered prefix while preserving newer events.
-
#size ⇒ Integer
private
Number of pending events.
-
#snapshot ⇒ Array<Hash>
private
Stable copy of pending events in insertion order.
Constructor Details
#initialize(capacity:) ⇒ PendingScoreQueue
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of PendingScoreQueue.
12 13 14 15 16 |
# File 'lib/langfuse/pending_score_queue.rb', line 12 def initialize(capacity:) @capacity = capacity @events = [] @mutex = Mutex.new end |
Instance Attribute Details
#capacity ⇒ Integer (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Maximum number of pending scores.
9 10 11 |
# File 'lib/langfuse/pending_score_queue.rb', line 9 def capacity @capacity end |
Instance Method Details
#empty? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns true when no events are pending.
58 59 60 |
# File 'lib/langfuse/pending_score_queue.rb', line 58 def empty? @mutex.synchronize { @events.empty? } end |
#first(limit) ⇒ Array<Hash>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return up to limit events from the front without removing them.
40 41 42 |
# File 'lib/langfuse/pending_score_queue.rb', line 40 def first(limit) @mutex.synchronize { @events.first(limit) } end |
#push(event) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Add an event without waiting for queue capacity.
22 23 24 25 26 27 28 29 |
# File 'lib/langfuse/pending_score_queue.rb', line 22 def push(event) @mutex.synchronize do return false if @events.length >= capacity @events << event true end end |
#remove_prefix(count) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Remove a delivered prefix while preserving newer events.
48 49 50 |
# File 'lib/langfuse/pending_score_queue.rb', line 48 def remove_prefix(count) @mutex.synchronize { @events.shift(count) } end |
#size ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Number of pending events.
53 54 55 |
# File 'lib/langfuse/pending_score_queue.rb', line 53 def size @mutex.synchronize { @events.size } end |
#snapshot ⇒ Array<Hash>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Stable copy of pending events in insertion order.
32 33 34 |
# File 'lib/langfuse/pending_score_queue.rb', line 32 def snapshot @mutex.synchronize { @events.dup } end |