Class: Rabbitek::Batcher

Inherits:
Object
  • Object
show all
Defined in:
lib/rabbitek/server/batcher.rb

Overview

A service to group messages from queue by batches.

Instance Method Summary collapse

Constructor Details

#initialize(consumer) ⇒ Batcher

Returns a new instance of Batcher.



7
8
9
10
11
# File 'lib/rabbitek/server/batcher.rb', line 7

def initialize(consumer)
  @consumer = consumer
  @batch_size = consumer.opts[:batch][:of]
  @batch = []
end

Instance Method Details

#perform(message) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/rabbitek/server/batcher.rb', line 13

def perform(message)
  collect_batch(message)
  yield(@batch)
rescue StandardError
  retry_all_messages
  raise
end