Sha256: dc5528121323bedb500d380d28873c2940f5c69d2588c675afd3de12b229a6bb

Contents?: true

Size: 747 Bytes

Versions: 2

Compression:

Stored size: 747 Bytes

Contents

require_relative 'logging'

module Upperkut
  class BatchExecution
    include Upperkut::Util

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

    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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
upperkut-0.7.2 lib/upperkut/batch_execution.rb
upperkut-0.7.1 lib/upperkut/batch_execution.rb