Sha256: 7608420712c6b8fec8e43948f031fa50e391df00dd19e86076f7b4509b06c1ce
Contents?: true
Size: 824 Bytes
Versions: 6
Compression:
Stored size: 824 Bytes
Contents
require 'digest' require 'multi_json' module Sidekiq module Middleware module Client class UniqueJobs HASH_KEY_EXPIRATION = 30 * 60 def call(worker_class, item, queue) enabled = worker_class.get_sidekiq_options['unique'] if enabled payload_hash = Digest::MD5.hexdigest(Sidekiq.dump_json(item)) unique = false Sidekiq.redis do |conn| conn.watch(payload_hash) if conn.get(payload_hash) conn.unwatch else unique = conn.multi do conn.setex(payload_hash, HASH_KEY_EXPIRATION, 1) end end end yield if unique else yield end end end end end end
Version data entries
6 entries across 6 versions & 2 rubygems