Class: Sidekiq::TransactionGuard::Middleware

Inherits:
Object
  • Object
show all
Includes:
ClientMiddleware
Defined in:
lib/sidekiq/transaction_guard/middleware.rb

Overview

Sidekiq client middleware that will warn/error when workers are called inside of a database transaction.

This middleware can read ‘sidekiq_options` set on the worker for `:transaction_guard` and `:notify_in_transaction` which will override the default behavior set in `Sidekiq::TransactionGuard.mode` and `Sidekiq::TransactionGuard.notify` respectively.

Instance Method Summary collapse

Instance Method Details

#call(worker_class, job, queue, redis_pool) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/sidekiq/transaction_guard/middleware.rb', line 15

def call(worker_class, job, queue, redis_pool)
  # Check if we need to log this. Also, convert worker_class to its actual class
  if in_transaction? && !sidekiq_inline?
    worker_class = worker_class.constantize if worker_class.is_a?(String)
    log_transaction(worker_class, job)
  end
  yield
end