Class: Sidekiq::Middleware::Client::UniqueJobs

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq/middleware/client/unique_jobs.rb

Constant Summary collapse

HASH_KEY_EXPIRATION =
30 * 60

Instance Method Summary collapse

Instance Method Details

#call(item, queue) ⇒ Object


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

def call(item, queue)
  payload_hash = Digest::MD5.hexdigest(MultiJson.encode(item))
  Sidekiq.redis.with_connection do |redis|
    return if redis.get(payload_hash)
    redis.setex(payload_hash, HASH_KEY_EXPIRATION, 1)
  end

  yield
end