Sha256: c24537999a33b5d31c9cee64732a28995a6c14928e46d82671c148228bbb6d4e

Contents?: true

Size: 485 Bytes

Versions: 2

Compression:

Stored size: 485 Bytes

Contents

require 'multi_json'
require 'digest'

module Sidekiq
  module Middleware
    module Client
      class UniqueJobs
        HASH_KEY_EXPIRATION = 30 * 60

        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
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sidekiq-0.8.0 lib/sidekiq/middleware/client/unique_jobs.rb
sidekiq-0.7.0 lib/sidekiq/middleware/client/unique_jobs.rb