Class: RailsAi::Performance::BatchProcessor
- Inherits:
-
Object
- Object
- RailsAi::Performance::BatchProcessor
- Defined in:
- lib/rails_ai/performance.rb
Overview
Request batching for multiple operations
Instance Method Summary collapse
- #add_operation(operation) ⇒ Object
-
#initialize(batch_size: 10, flush_interval: 0.1) ⇒ BatchProcessor
constructor
A new instance of BatchProcessor.
Constructor Details
#initialize(batch_size: 10, flush_interval: 0.1) ⇒ BatchProcessor
Returns a new instance of BatchProcessor.
31 32 33 34 35 36 37 |
# File 'lib/rails_ai/performance.rb', line 31 def initialize(batch_size: 10, flush_interval: 0.1) @batch_size = batch_size @flush_interval = flush_interval @queue = Concurrent::Array.new @mutex = Mutex.new @last_flush = Time.now end |
Instance Method Details
#add_operation(operation) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/rails_ai/performance.rb', line 39 def add_operation(operation) @mutex.synchronize do @queue << operation flush_if_needed end end |