Class: ConsistentRandom::SidekiqMiddleware

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

Overview

Sidekiq server middleware that wraps job execution with consistent random scope so that you can generate consistent random values within a job.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.installObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/consistent_random/sidekiq_middleware.rb', line 12

def install
  Sidekiq.configure_server do |config|
    config.server_middleware do |chain|
      chain.prepend ConsistentRandom::SidekiqMiddleware
    end

    config.client_middleware do |chain|
      chain.add ConsistentRandom::SidekiqClientMiddleware
    end
  end

  Sidekiq.configure_client do |config|
    config.client_middleware do |chain|
      chain.add ConsistentRandom::SidekiqClientMiddleware
    end
  end
end

Instance Method Details

#call(job_instance, job_payload, queue) ⇒ Object



31
32
33
34
35
# File 'lib/consistent_random/sidekiq_middleware.rb', line 31

def call(job_instance, job_payload, queue)
  ConsistentRandom.scope(job_payload["consistent_random_seed"]) do
    yield
  end
end