mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
f9af66edd7
the client use separate pools. This is so the Rails app Sidekiq::Client and Sidekiq::Manager can use different configurations. Also, fix issue where workers were not unregistered in Redis upon shutdown.
30 lines
586 B
Ruby
30 lines
586 B
Ruby
require 'digest'
|
|
|
|
module Sidekiq
|
|
module Middleware
|
|
module Client
|
|
class UniqueJobs
|
|
HASH_KEY_EXPIRATION = 30 * 60
|
|
|
|
def initialize(redis)
|
|
@redis = redis
|
|
end
|
|
|
|
def call(item, queue)
|
|
payload_hash = Digest::MD5.hexdigest(MultiJson.encode(item))
|
|
return if already_scheduled?(payload_hash)
|
|
|
|
@redis.setex(payload_hash, HASH_KEY_EXPIRATION, 1)
|
|
|
|
yield
|
|
end
|
|
|
|
private
|
|
|
|
def already_scheduled?(payload_hash)
|
|
!!@redis.get(payload_hash)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|