Class: RailsAi::Performance::BatchProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_ai/performance.rb

Overview

Request batching for multiple operations

Instance Method Summary collapse

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