Sha256: b0ff9757700ea24b03975d0e36c9185b946979fa648f1093ab02f16564e96e11

Contents?: true

Size: 1016 Bytes

Versions: 3

Compression:

Stored size: 1016 Bytes

Contents

# frozen_string_literal: true

module Labkit
  module Middleware
    module Sidekiq
      module Context
        # This middleware for Sidekiq-client wraps scheduling jobs in a context
        # The context will also be added to the sidekiq job in redis so it can
        # be reinstantiated by Sidekiq-server when running the job.
        class Client
          def call(_worker_class, job, _queue, _redis_pool)
            attributes = {}

            # Don't overwrite the correlation_id from the job. A new context
            # will always generate a new correlation_id and we'd rather carry
            # through the correlation_id from the previous job if it is
            # present (eg. for retries).
            attributes[Labkit::Context::CORRELATION_ID_KEY] = job["correlation_id"] if job["correlation_id"]

            Labkit::Context.with_context(attributes) do |context|
              job.merge!(context.to_h)

              yield
            end
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
gitlab-labkit-0.36.1 lib/labkit/middleware/sidekiq/context/client.rb
gitlab-labkit-0.36.0 lib/labkit/middleware/sidekiq/context/client.rb
gitlab-labkit-0.35.1 lib/labkit/middleware/sidekiq/context/client.rb