Class: Sqreen::Kit::Signals::BatchCollector
- Inherits:
-
Object
- Object
- Sqreen::Kit::Signals::BatchCollector
- Includes:
- Loggable
- Defined in:
- lib/sqreen/kit/signals/batch_collector.rb
Defined Under Namespace
Classes: ProcessingLoop, QueueWithTimeout
Constant Summary collapse
- EXIT_SENTINEL =
Object.new.freeze
- DEFAULT_MAX_DELAY_S =
45
- DEFAULT_FLUSH_SIZE =
30
- DEFAULT_MAX_BATCH_SIZE =
100
Instance Attribute Summary collapse
-
#auth_sig_client ⇒ Object
readonly
Returns the value of attribute auth_sig_client.
-
#flush_size ⇒ Object
readonly
Returns the value of attribute flush_size.
-
#max_batch_size ⇒ Object
readonly
Returns the value of attribute max_batch_size.
-
#max_delay_s ⇒ Object
readonly
Returns the value of attribute max_delay_s.
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
Instance Method Summary collapse
- #<<(signal_or_trace) ⇒ Object
- #close ⇒ Object
-
#initialize(auth_sig_client, opts = {}) ⇒ BatchCollector
constructor
A new instance of BatchCollector.
- #running? ⇒ Boolean
- #start ⇒ Object
Constructor Details
#initialize(auth_sig_client, opts = {}) ⇒ BatchCollector
Returns a new instance of BatchCollector.
26 27 28 29 30 31 32 33 34 35 36 37 |
# 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 |
Instance Attribute Details
#auth_sig_client ⇒ Object (readonly)
Returns the value of attribute auth_sig_client.
19 20 21 |
# File 'lib/sqreen/kit/signals/batch_collector.rb', line 19 def auth_sig_client @auth_sig_client end |
#flush_size ⇒ Object (readonly)
Returns the value of attribute flush_size.
19 20 21 |
# File 'lib/sqreen/kit/signals/batch_collector.rb', line 19 def flush_size @flush_size end |
#max_batch_size ⇒ Object (readonly)
Returns the value of attribute max_batch_size.
19 20 21 |
# File 'lib/sqreen/kit/signals/batch_collector.rb', line 19 def max_batch_size @max_batch_size end |
#max_delay_s ⇒ Object (readonly)
Returns the value of attribute max_delay_s.
19 20 21 |
# File 'lib/sqreen/kit/signals/batch_collector.rb', line 19 def max_delay_s @max_delay_s end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
19 20 21 |
# File 'lib/sqreen/kit/signals/batch_collector.rb', line 19 def queue @queue end |
Instance Method Details
#<<(signal_or_trace) ⇒ Object
39 40 41 |
# File 'lib/sqreen/kit/signals/batch_collector.rb', line 39 def <<(signal_or_trace) @queue << signal_or_trace end |
#close ⇒ Object
55 56 57 58 59 60 |
# File 'lib/sqreen/kit/signals/batch_collector.rb', line 55 def close return if @thread.nil? @queue << EXIT_SENTINEL @thread.join end |
#running? ⇒ Boolean
50 51 52 53 |
# File 'lib/sqreen/kit/signals/batch_collector.rb', line 50 def running? return false if thread.nil? @thread.alive? end |
#start ⇒ Object
43 44 45 46 47 48 |
# 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 |