Sha256: f3125e0038dbf8793da1c0829f0edae5b1d114ba0eaf75d24f132788764001c6

Contents?: true

Size: 946 Bytes

Versions: 9

Compression:

Stored size: 946 Bytes

Contents

require_relative '../lib/upperkut/worker'
require_relative '../lib/upperkut/logging'

class ClientMiddleware
  def call(worker, items)
    logger = Upperkut::Logging.logger

    logger.info("inserting worker=#{worker} items=#{items.count}")
    yield
    logger.info("inserted worker=#{worker} items=#{items.count}")
  end
end

class MyMiddleware
  def call(worker, items)
    logger = Upperkut::Logging.logger

    logger.info("performing worker=#{worker} items=#{items.count}")
    yield
    logger.info("performed worker=#{worker} items=#{items.count}")
  end
end

class WithMiddlewares
  include Upperkut::Worker

  setup_upperkut do |config|
    config.server_middlewares do |chain|
      chain.add MyMiddleware
    end

    config.client_middlewares do |chain|
      chain.add ClientMiddleware
    end
  end

  def perform(_items)
    puts 'executing.........'
    exec_time = rand(80..200)
    sleep (exec_time.to_f / 1000.to_f)
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
upperkut-1.0.4 examples/with_middlewares.rb
upperkut-1.0.2 examples/with_middlewares.rb
upperkut-1.0.0.rc examples/with_middlewares.rb
upperkut-0.8.1 examples/with_middlewares.rb
upperkut-0.8.0 examples/with_middlewares.rb
upperkut-0.7.5 examples/with_middlewares.rb
upperkut-0.7.4 examples/with_middlewares.rb
upperkut-0.7.2 examples/with_middlewares.rb
upperkut-0.7.1 examples/with_middlewares.rb