Class: Bugwatch::TransactionBuffer
- Inherits:
-
Object
- Object
- Bugwatch::TransactionBuffer
- Defined in:
- lib/bugwatch/transaction_buffer.rb
Constant Summary collapse
- BATCH_SIZE =
50- FLUSH_INTERVAL =
seconds
10
Instance Method Summary collapse
- #flush ⇒ Object
-
#initialize(config: Bugwatch.configuration) ⇒ TransactionBuffer
constructor
A new instance of TransactionBuffer.
- #push(payload) ⇒ Object
- #shutdown ⇒ Object
Constructor Details
#initialize(config: Bugwatch.configuration) ⇒ TransactionBuffer
Returns a new instance of TransactionBuffer.
6 7 8 9 10 11 12 |
# File 'lib/bugwatch/transaction_buffer.rb', line 6 def initialize(config: Bugwatch.configuration) @config = config @sender = TransactionSender.new(config: config) @mutex = Mutex.new @buffer = [] start_flusher end |
Instance Method Details
#flush ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/bugwatch/transaction_buffer.rb', line 25 def flush batch = @mutex.synchronize do items = @buffer @buffer = [] items end @sender.send_batch(batch) unless batch.empty? rescue StandardError # Never let flushing break the app end |
#push(payload) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/bugwatch/transaction_buffer.rb', line 14 def push(payload) should_flush = false @mutex.synchronize do @buffer << payload should_flush = @buffer.size >= BATCH_SIZE end flush if should_flush end |
#shutdown ⇒ Object
37 38 39 40 |
# File 'lib/bugwatch/transaction_buffer.rb', line 37 def shutdown stop_flusher flush end |