Sha256: 1ea51a7801d5cb9f222db122296a41a477fcd8f62ee9b5228468a89696f4ca6f

Contents?: true

Size: 696 Bytes

Versions: 3

Compression:

Stored size: 696 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.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
      )

      raise ex
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
upperkut-0.4.4 lib/upperkut/batch_execution.rb
upperkut-0.4.3 lib/upperkut/batch_execution.rb
upperkut-0.4.2 lib/upperkut/batch_execution.rb