Class: RubyLLM::Ups::AsyncReporter
- Inherits:
-
Object
- Object
- RubyLLM::Ups::AsyncReporter
- Defined in:
- lib/ruby_llm/ups/async_reporter.rb
Constant Summary collapse
- CLOSED =
:closed- OPEN =
:open- HALF_OPEN =
:half_open
Instance Method Summary collapse
- #enqueue(component_id, status:, agent_metadata:) ⇒ Object
- #flush_now ⇒ Object
-
#initialize(client, config) ⇒ AsyncReporter
constructor
A new instance of AsyncReporter.
- #running? ⇒ Boolean
- #shutdown(timeout: 2) ⇒ Object
Constructor Details
#initialize(client, config) ⇒ AsyncReporter
Returns a new instance of AsyncReporter.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ruby_llm/ups/async_reporter.rb', line 10 def initialize(client, config) @client = client @config = config @buffer = {} @mutex = Mutex.new @signal = Queue.new @thread = nil @shutdown = false @at_exit_registered = false # Circuit breaker state @cb_state = CLOSED @consecutive_failures = 0 @opened_at = nil end |
Instance Method Details
#enqueue(component_id, status:, agent_metadata:) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/ruby_llm/ups/async_reporter.rb', line 26 def enqueue(component_id, status:, agent_metadata:) @mutex.synchronize do @buffer[component_id] = { status: status, agent_metadata: } end ensure_running @signal.push(:enqueue) rescue nil # wake the worker end |
#flush_now ⇒ Object
44 45 46 47 |
# File 'lib/ruby_llm/ups/async_reporter.rb', line 44 def flush_now entries = drain_buffer flush_entries(entries) unless entries.empty? end |
#running? ⇒ Boolean
40 41 42 |
# File 'lib/ruby_llm/ups/async_reporter.rb', line 40 def running? @thread&.alive? == true end |
#shutdown(timeout: 2) ⇒ Object
34 35 36 37 38 |
# File 'lib/ruby_llm/ups/async_reporter.rb', line 34 def shutdown(timeout: 2) @mutex.synchronize { @shutdown = true } @signal.push(:shutdown) rescue nil @thread&.join(timeout) end |