Sha256: 738737bd1013473a76ade21c82d81b3db97de4fabb8b1c19fc518d582fb579a9

Contents?: true

Size: 1.08 KB

Versions: 7

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module SuperSettings
  module Context
    # Sidekiq middleware you can use to add a context to your jobs so that
    # settings are not changed during job execution.
    #
    # @example
    #   require "super_settings/context/sidekiq_middleware"
    #
    #   Sidekiq.configure_server do |config|
    #     config.server_middleware do |chain|
    #       chain.add SuperSettings::Context::SidekiqMiddleware
    #     end
    #   end
    #
    # You can disable the context by setting the `super_settings_context` key
    # to `false` in the job payload.
    #
    # @example
    #   class MyWorker
    #     include Sidekiq::Worker
    #     sidekiq_options super_settings_context: false
    #   end
    class SidekiqMiddleware
      if defined?(Sidekiq::ServerMiddleware)
        include Sidekiq::ServerMiddleware
      end

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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
super_settings-2.0.3 lib/super_settings/context/sidekiq_middleware.rb
super_settings-2.0.2 lib/super_settings/context/sidekiq_middleware.rb
super_settings-2.0.1 lib/super_settings/context/sidekiq_middleware.rb
super_settings-2.0.0 lib/super_settings/context/sidekiq_middleware.rb
super_settings-1.0.2 lib/super_settings/context/sidekiq_middleware.rb
super_settings-1.0.1 lib/super_settings/context/sidekiq_middleware.rb
super_settings-1.0.0 lib/super_settings/context/sidekiq_middleware.rb