class Sqreen::Kit::Signals::BatchCollector

Constants

DEFAULT_FLUSH_SIZE
DEFAULT_MAX_BATCH_SIZE
DEFAULT_MAX_DELAY_S
EXIT_SENTINEL

Attributes

auth_sig_client[R]
flush_size[R]
max_batch_size[R]
max_delay_s[R]
queue[R]

Public Class Methods

new(auth_sig_client, opts = {}) click to toggle source

@param auth_sig_client [AuthSignalsClient]

# File lib/sqreen/kit/signals/batch_collector.rb, line 26
def initialize(auth_sig_client, opts = {})
  @auth_sig_client = auth_sig_client
  @flush_size = opts[:flush_size] || DEFAULT_FLUSH_SIZE
  @max_batch_size = opts[:max_batch_size] || DEFAULT_MAX_BATCH_SIZE
  @max_delay_s = opts[:max_delay_s] || DEFAULT_MAX_DELAY_S
  @queue = QueueWithTimeout.new
  @thread = nil

  if max_batch_size < flush_size # rubocop:disable Style/GuardClause
    raise ArgumentError, 'max batch size < flush size'
  end
end

Public Instance Methods

<<(signal_or_trace) click to toggle source
# File lib/sqreen/kit/signals/batch_collector.rb, line 39
def <<(signal_or_trace)
  @queue << signal_or_trace
end
close() click to toggle source
# File lib/sqreen/kit/signals/batch_collector.rb, line 55
def close
  return if @thread.nil?

  @queue << EXIT_SENTINEL
  @thread.join
end
running?() click to toggle source
# File lib/sqreen/kit/signals/batch_collector.rb, line 50
def running?
  return false if thread.nil?
  @thread.alive?
end
start() click to toggle source
# File lib/sqreen/kit/signals/batch_collector.rb, line 43
def start
  @processing_loop = ProcessingLoop.new(self)
  @thread = Thread.new do
    @processing_loop.run
  end
end