Class: SuperSettings::Context::SidekiqMiddleware

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::ServerMiddleware
Defined in:
lib/super_settings/context/sidekiq_middleware.rb

Overview

Sidekiq middleware you can use to add a context to your jobs so that settings are not changed during job execution.

You can disable the context by setting the ‘super_settings_context` key to `false` in the job payload.

Examples:

require "super_settings/context/sidekiq_middleware"

Sidekiq.configure_server do |config|
  config.server_middleware do |chain|
    chain.add SuperSettings::Context::SidekiqMiddleware
  end
end
class MyWorker
  include Sidekiq::Worker
  sidekiq_options super_settings_context: false
end

Instance Method Summary collapse

Instance Method Details

#call(job_instance, job_payload, queue) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/super_settings/context/sidekiq_middleware.rb', line 30

def call(job_instance, job_payload, queue)
  if job_payload["super_settings_context"] == false
    yield
  else
    SuperSettings.context do
      yield
    end
  end
end