Module: Sidekiq::CurrentAttributes

Defined in:
lib/sidekiq/middleware/current_attributes.rb

Overview

Automatically save and load any current attributes in the execution context so context attributes “flow” from Rails actions into any associated jobs. This can be useful for multi-tenancy, i18n locale, timezone, any implicit per-request attribute. See ActiveSupport::CurrentAttributes.

For multiple current attributes, pass an array of current attributes.

Examples:


# in your initializer
require "sidekiq/middleware/current_attributes"
Sidekiq::CurrentAttributes.persist("Myapp::Current")
# or multiple current attributes
Sidekiq::CurrentAttributes.persist(["Myapp::Current", "Myapp::OtherCurrent"])

Defined Under Namespace

Classes: Load, Save

Class Method Summary collapse

Class Method Details

.persist(klass_or_array, config = Sidekiq.default_configuration) ⇒ Object



69
70
71
72
73
74
# File 'lib/sidekiq/middleware/current_attributes.rb', line 69

def persist(klass_or_array, config = Sidekiq.default_configuration)
  cattrs = build_cattrs_hash(klass_or_array)

  config.client_middleware.add Save, cattrs
  config.server_middleware.add Load, cattrs
end