Module: SidekiqCurrentModelMiddleware
- Defined in:
- lib/sidekiq_current_model_middleware.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.
SidekiqCurrentModelMiddleware module
This module provides middleware for Sidekiq to persist ActiveSupport::CurrentAttributes across job boundaries, including support for ActiveRecord models.
It extends the functionality of Sidekiq’s built-in CurrentAttributes middleware by adding serialization and deserialization of ActiveRecord models using GlobalID.
Defined Under Namespace
Class Method Summary collapse
-
.persist(klass_or_array, config = ::Sidekiq.default_configuration) ⇒ Object
Persist CurrentAttributes across Sidekiq job boundaries.
Class Method Details
.persist(klass_or_array, config = ::Sidekiq.default_configuration) ⇒ Object
Persist CurrentAttributes across Sidekiq job boundaries
151 152 153 154 155 156 |
# File 'lib/sidekiq_current_model_middleware.rb', line 151 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 |