Class: Langfuse::PendingScoreQueue Private

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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.

Parameters:

  • capacity (Integer)

    Maximum number of pending scores



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

#capacityInteger (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.

Returns:

  • (Integer)

    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.

Returns:

  • (Boolean)

    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.

Parameters:

  • limit (Integer)

    Maximum number of events to return

Returns:

  • (Array<Hash>)

    Stable copy of the pending prefix



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.

Parameters:

  • event (Hash)

    Score ingestion event

Returns:

  • (Boolean)

    true when accepted, false when full



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.

Parameters:

  • count (Integer)

    Number of delivered events



48
49
50
# File 'lib/langfuse/pending_score_queue.rb', line 48

def remove_prefix(count)
  @mutex.synchronize { @events.shift(count) }
end

#sizeInteger

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.

Returns:

  • (Integer)

    Number of pending events



53
54
55
# File 'lib/langfuse/pending_score_queue.rb', line 53

def size
  @mutex.synchronize { @events.size }
end

#snapshotArray<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.

Returns:

  • (Array<Hash>)

    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