Module: Sidekiq::Middleware

Defined in:
lib/sidekiq/middleware/chain.rb,
lib/sidekiq/middleware/server/logging.rb,
lib/sidekiq/middleware/server/timeout.rb,
lib/sidekiq/middleware/server/retry_jobs.rb,
lib/sidekiq/middleware/client/unique_jobs.rb,
lib/sidekiq/middleware/server/unique_jobs.rb,
lib/sidekiq/middleware/server/failure_jobs.rb,
lib/sidekiq/middleware/server/active_record.rb,
lib/sidekiq/middleware/server/exception_handler.rb

Overview

Middleware is code configured to run before/after a message is processed. It is patterned after Rack middleware. Middleware exists for the client side (pushing jobs onto the queue) as well as the server side (when jobs are actually processed).

To add middleware for the client:

Sidekiq.client_middleware do |chain|

chain.add MyClientHook

end

To modify middleware for the server, just call with another block:

Sidekiq.server_middleware do |chain|

chain.add MyServerHook
chain.remove ActiveRecord

end

This is an example of a minimal server middleware:

class MyServerHook

def call(worker, msg, queue)
  puts "Before work"
  yield
  puts "After work"
end

end

This is an example of a minimal client middleware:

class MyClientHook

def call(msg, queue)
  puts "Before push"
  yield
  puts "After push"
end

end

Defined Under Namespace

Modules: Client, Server Classes: Chain, Entry