Skip to content

Miscellaneous Features

Mike Perham edited this page Jul 29, 2022 · 1 revision

CurrentAttributes

Rails' CurrentAttributes allows you to set request-specific attributes which are accessible to any code executing during that request. For example, you can implement multi-tenancy by setting a tenant_id associated with each request.

Sidekiq supports persisting these attributes into every job payload to preserve any implicit state. Sidekiq will restore these attributes when the job executes.

# config/initializers/sidekiq.rb, see issue #4982
require "sidekiq/middleware/current_attributes"
Sidekiq::CurrentAttributes.persist(Myapp::Current) # Your AS::CurrentAttributes singleton