Class: Errsight::Client
- Inherits:
-
Object
- Object
- Errsight::Client
- Defined in:
- lib/errsight/client.rb
Instance Method Summary collapse
- #enqueue(event) ⇒ Object
- #flush! ⇒ Object
-
#initialize(config) ⇒ Client
constructor
A new instance of Client.
- #shutdown! ⇒ Object
Constructor Details
#initialize(config) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 14 |
# File 'lib/errsight/client.rb', line 9 def initialize(config) @config = config @queue = Concurrent::Array.new @mutex = Mutex.new start_flush_worker end |
Instance Method Details
#enqueue(event) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/errsight/client.rb', line 16 def enqueue(event) if @queue.size >= @config.max_queue_size @config.logger&.warn("[Errsight] Queue full (#{@config.max_queue_size}), dropping event") return end @queue << event flush! if @queue.size >= @config.batch_size end |
#flush! ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/errsight/client.rb', line 25 def flush! events = nil @mutex.synchronize do return if @queue.empty? events = @queue.slice!(0, @config.batch_size) end send_events(events) if events&.any? end |
#shutdown! ⇒ Object
34 35 36 37 |
# File 'lib/errsight/client.rb', line 34 def shutdown! @flush_thread&.exit flush! # Drain remaining events synchronously end |