Sha256: 5c17b4686b98f608c081d7af49b937c885d601c70f527ee12878186a803d238b

Contents?: true

Size: 887 Bytes

Versions: 2

Compression:

Stored size: 887 Bytes

Contents

# frozen_string_literal: true

module SidekiqUniqueJobs
  class Lock
    class WhileExecuting < BaseLock
      RUN_SUFFIX ||= ':RUN'

      def initialize(item, redis_pool = nil)
        super(item, redis_pool)
        append_unique_key_suffix
      end

      # Returning true makes sure the client
      #   can push the job on the queue
      def lock
        true
      end

      # Locks the job with the RUN_SUFFIX appended
      def execute(callback)
        return unless locksmith.lock(item[LOCK_TIMEOUT_KEY])

        using_protection(callback) do
          yield if block_given?
        end
      end

      private

      # This is safe as the base_lock always creates a new digest
      #   The append there for needs to be done every time
      def append_unique_key_suffix
        item[UNIQUE_DIGEST_KEY] = item[UNIQUE_DIGEST_KEY] + RUN_SUFFIX
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sidekiq-unique-jobs-6.0.0.rc2 lib/sidekiq_unique_jobs/lock/while_executing.rb
sidekiq-unique-jobs-6.0.0.rc1 lib/sidekiq_unique_jobs/lock/while_executing.rb