Class: Labkit::Middleware::Sidekiq::Context::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/labkit/middleware/sidekiq/context/server.rb

Overview

This middleware for Sidekiq-client uses the values stored on a job to reinstantiate a context in which the job will run.

Instance Method Summary collapse

Instance Method Details

#call(_worker_class, job, _queue) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/labkit/middleware/sidekiq/context/server.rb', line 10

def call(_worker_class, job, _queue)
  worker_name = (job["wrapped"].presence || job["class"]).to_s
  data = job.merge(Labkit::Context.log_key(:caller_id) => worker_name)
            .select { |key, _| key.start_with?("#{Labkit::Context::LOG_KEY}.") || Labkit::Context::RAW_KEYS.include?(key.to_s) }

  Labkit::Context.with_context(data) do |_context|
    yield
  end
end