Class: ConsistentRandom::SidekiqClientMiddleware

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::ClientMiddleware
Defined in:
lib/consistent_random/sidekiq_client_middleware.rb

Overview

Sidekiq client middleware that adds the current seeds to the job options. These seeds will be deserialized and used when the job is run on the server so that the client and server can share consistent random values.

Instance Method Summary collapse

Instance Method Details

#call(job_class_or_string, job, queue, redis_pool) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/consistent_random/sidekiq_client_middleware.rb', line 12

def call(job_class_or_string, job, queue, redis_pool)
  unless job["consistent_random"] == false
    seed = ConsistentRandom.current_seed
    job["consistent_random_seed"] = seed unless seed.nil?
  end
  yield
end