Sha256: ed52cffbe4d3ab64afc0c395ae49052d76a3cf1be6f0cfb6f23f7c73384df015

Contents?: true

Size: 1004 Bytes

Versions: 18

Compression:

Stored size: 1004 Bytes

Contents

# frozen_string_literal: true

module SidekiqUniqueJobs
  module Middleware
    # The unique sidekiq middleware for the client push
    #
    # @author Mikael Henriksson <mikael@mhenrixon.com>
    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(*, &block)
        lock(&block)
      end

      private

      def lock
        if (_token = lock_instance.lock)
          yield
        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

18 entries across 18 versions & 1 rubygems

Version Path
sidekiq-unique-jobs-7.0.13 lib/sidekiq_unique_jobs/middleware/client.rb
sidekiq-unique-jobs-7.0.12 lib/sidekiq_unique_jobs/middleware/client.rb
sidekiq-unique-jobs-7.0.11 lib/sidekiq_unique_jobs/middleware/client.rb
sidekiq-unique-jobs-7.0.10 lib/sidekiq_unique_jobs/middleware/client.rb
sidekiq-unique-jobs-7.0.9 lib/sidekiq_unique_jobs/middleware/client.rb
sidekiq-unique-jobs-7.0.8 lib/sidekiq_unique_jobs/middleware/client.rb
sidekiq-unique-jobs-7.0.7 lib/sidekiq_unique_jobs/middleware/client.rb
sidekiq-unique-jobs-7.0.6 lib/sidekiq_unique_jobs/middleware/client.rb
sidekiq-unique-jobs-7.0.5 lib/sidekiq_unique_jobs/middleware/client.rb
sidekiq-unique-jobs-7.0.4 lib/sidekiq_unique_jobs/middleware/client.rb
sidekiq-unique-jobs-7.0.3 lib/sidekiq_unique_jobs/middleware/client.rb
sidekiq-unique-jobs-7.0.2 lib/sidekiq_unique_jobs/middleware/client.rb
sidekiq-unique-jobs-7.0.1 lib/sidekiq_unique_jobs/middleware/client.rb
sidekiq-unique-jobs-7.0.0 lib/sidekiq_unique_jobs/middleware/client.rb
sidekiq-unique-jobs-7.0.0.beta29 lib/sidekiq_unique_jobs/middleware/client.rb
sidekiq-unique-jobs-7.0.0.beta28 lib/sidekiq_unique_jobs/middleware/client.rb
sidekiq-unique-jobs-7.0.0.beta27 lib/sidekiq_unique_jobs/middleware/client.rb
sidekiq-unique-jobs-7.0.0.beta26 lib/sidekiq_unique_jobs/middleware/client.rb