Sha256: 936dfee9cab5ac38f7692e8f3362ab7cd1180947d91f396f3a536d9bbd4947eb

Contents?: true

Size: 1003 Bytes

Versions: 22

Compression:

Stored size: 1003 Bytes

Contents

# frozen_string_literal: true

module SidekiqUniqueJobs
  module Middleware
    # The unique sidekiq middleware for the client push
    #
    # @author Mikael Henriksson <mikael@zoolutions.se>
    class Client
      prepend SidekiqUniqueJobs::Middleware

      # Calls this client middleware
      #   Used from Sidekiq.process_single
      #
      # @see SidekiqUniqueJobs::Middleware#call
      #
      # @see https://github.com/mperham/sidekiq/wiki/Job-Format
      # @see https://github.com/mperham/sidekiq/wiki/Middleware
      #
      # @yield when uniqueness is disable
      # @yield when the lock is successful
      def call(*)
        lock { yield }
      end

      private

      def lock
        if (token = lock_instance.lock)
          yield token
        else
          warn_about_duplicate
        end
      end

      def warn_about_duplicate
        return unless log_duplicate?

        log_warn "Already locked with another job_id (#{dump_json(item)})"
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
sidekiq-unique-jobs-7.0.0.beta23 lib/sidekiq_unique_jobs/middleware/client.rb
sidekiq-unique-jobs-7.0.0.beta22 lib/sidekiq_unique_jobs/middleware/client.rb
sidekiq-unique-jobs-7.0.0.beta21 lib/sidekiq_unique_jobs/middleware/client.rb
sidekiq-unique-jobs-7.0.0.beta20 lib/sidekiq_unique_jobs/middleware/client.rb
sidekiq-unique-jobs-7.0.0.beta19 lib/sidekiq_unique_jobs/middleware/client.rb
sidekiq-unique-jobs-7.0.0.beta18 lib/sidekiq_unique_jobs/middleware/client.rb
sidekiq-unique-jobs-7.0.0.beta17 lib/sidekiq_unique_jobs/middleware/client.rb
sidekiq-unique-jobs-7.0.0.beta16 lib/sidekiq_unique_jobs/middleware/client.rb
sidekiq-unique-jobs-7.0.0.beta15 lib/sidekiq_unique_jobs/middleware/client.rb
sidekiq-unique-jobs-7.0.0.beta14 lib/sidekiq_unique_jobs/middleware/client.rb
sidekiq-unique-jobs-7.0.0.beta13 lib/sidekiq_unique_jobs/middleware/client.rb
sidekiq-unique-jobs-7.0.0.beta12 lib/sidekiq_unique_jobs/middleware/client.rb
sidekiq-unique-jobs-7.0.0.beta11 lib/sidekiq_unique_jobs/middleware/client.rb
sidekiq-unique-jobs-7.0.0.beta10 lib/sidekiq_unique_jobs/middleware/client.rb
sidekiq-unique-jobs-7.0.0.beta9 lib/sidekiq_unique_jobs/middleware/client.rb
sidekiq-unique-jobs-7.0.0.beta8 lib/sidekiq_unique_jobs/middleware/client.rb
sidekiq-unique-jobs-7.0.0.beta7 lib/sidekiq_unique_jobs/middleware/client.rb
sidekiq-unique-jobs-7.0.0.beta6 lib/sidekiq_unique_jobs/middleware/client.rb
sidekiq-unique-jobs-7.0.0.beta5 lib/sidekiq_unique_jobs/middleware/client.rb
sidekiq-unique-jobs-7.0.0.beta4 lib/sidekiq_unique_jobs/middleware/client.rb