Class: SolidObserver::Services::FlushEventBuffer
- Inherits:
-
Object
- Object
- SolidObserver::Services::FlushEventBuffer
- Defined in:
- lib/solid_observer/services/flush_event_buffer.rb
Overview
Flushes buffered events to the database using bulk insert.
Attempts bulk insert with automatic fallback to smaller batches if the initial insert fails.
Constant Summary collapse
- BATCH_SIZE =
100
Class Method Summary collapse
-
.call(events) ⇒ Integer
Number of events successfully inserted.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(events) ⇒ FlushEventBuffer
constructor
A new instance of FlushEventBuffer.
Constructor Details
#initialize(events) ⇒ FlushEventBuffer
Returns a new instance of FlushEventBuffer.
21 22 23 24 |
# File 'lib/solid_observer/services/flush_event_buffer.rb', line 21 def initialize(events) @events = events @failed_count = 0 end |
Class Method Details
.call(events) ⇒ Integer
Returns Number of events successfully inserted.
17 18 19 |
# File 'lib/solid_observer/services/flush_event_buffer.rb', line 17 def self.call(events) new(events).call end |
Instance Method Details
#call ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/solid_observer/services/flush_event_buffer.rb', line 26 def call return 0 if @events.empty? bulk_insert @events.size rescue ActiveRecord::RecordInvalid, ActiveRecord::StatementInvalid => e handle_bulk_insert_failure(e) end |