Sha256: 821ccb92b40475117a648ce89b7d81f4ee5234a18f0f10c177aac8373d82e61b

Contents?: true

Size: 861 Bytes

Versions: 3

Compression:

Stored size: 861 Bytes

Contents

# frozen_string_literal: true

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

      def initialize(item, callback, redis_pool = nil)
        super(item, callback, 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
        return unless locksmith.lock(item[LOCK_TIMEOUT_KEY])
        with_cleanup { yield if block_given? }
      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

3 entries across 3 versions & 1 rubygems

Version Path
sidekiq-unique-jobs-6.0.0.rc6 lib/sidekiq_unique_jobs/lock/while_executing.rb
sidekiq-unique-jobs-6.0.0.rc5 lib/sidekiq_unique_jobs/lock/while_executing.rb
sidekiq-unique-jobs-6.0.0.rc4 lib/sidekiq_unique_jobs/lock/while_executing.rb