Class: Semlogr::Sinks::Batching

Inherits:
Object
  • Object
show all
Defined in:
lib/semlogr/sinks/batching.rb

Constant Summary collapse

MAX_FLUSH_ATTEMPTS =
6

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Batching

Returns a new instance of Batching.



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/semlogr/sinks/batching.rb', line 12

def initialize(opts = {})
  @flush_interval = opts[:flush_interval] || 3
  @final_flush_timeout = opts[:final_flush_timeout] || 60
  @batch_size = opts[:batch_size] || 1_000
  @queue_max_size = opts[:queue_max_size] || 100_000
  @queue = Utils::BoundedQueue.new(@queue_max_size)
  @flush_mutex = Mutex.new
  @running = false

  start_flush_thread

  at_exit { stop_flush_thread }
end

Instance Method Details

#emit(log_event) ⇒ Object



26
27
28
29
30
# File 'lib/semlogr/sinks/batching.rb', line 26

def emit(log_event)
  return unless @running

  @queue.push(log_event)
end