Class: Upperkut::BatchExecution

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/upperkut/batch_execution.rb

Instance Method Summary collapse

Methods included from Util

#decode_json_items, #encode_json_items, #to_underscore

Constructor Details

#initialize(worker, logger = Upperkut::Logging.logger) ⇒ BatchExecution

Returns a new instance of BatchExecution.



7
8
9
10
# File 'lib/upperkut/batch_execution.rb', line 7

def initialize(worker, logger = Upperkut::Logging.logger)
  @worker = worker
  @logger = logger
end

Instance Method Details

#executeObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/upperkut/batch_execution.rb', line 12

def execute
  worker_instance = @worker.new
  items = @worker.fetch_items.freeze

  items_body = items.collect do |item|
    item['body']
  end

  @worker.server_middlewares.invoke(@worker, items) do
    worker_instance.perform(items_body.dup)
  end
rescue Exception => ex
  @worker.push_items(items_body)

  @logger.info(
    action: :requeue,
    ex: ex,
    item_size: items_body.size
  )

  @logger.error(ex.backtrace.join("\n"))
  raise ex
end