Sha256: 90985c7de121c5e1b281bcdd6c427715416e2a80106bdd016d0a0fb8f5b734be

Contents?: true

Size: 1.27 KB

Versions: 3

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

module SidekiqUniqueJobs
  class Lock
    # Locks jobs while the job is executing in the server process
    # - Locks on perform_in or perform_async (see {UntilExecuting})
    # - Unlocks before yielding to the worker's perform method (see {UntilExecuting})
    # - Locks before yielding to the worker's perform method (see {WhileExecuting})
    # - Unlocks after yielding to the worker's perform method (see {WhileExecuting})
    #
    # See {#lock} for more information about the client.
    # See {#execute} for more information about the server
    #
    # @author Mikael Henriksson <mikael@zoolutions.se>
    class UntilAndWhileExecuting < BaseLock
      # Executes in the Sidekiq server process
      # @yield to the worker class perform method
      def execute
        if unlock
          runtime_lock.execute { return yield }
        else
          log_warn "couldn't unlock digest: #{item[UNIQUE_DIGEST]} #{item[JID]}"
        end
      end

      #
      # Lock only when the server is processing the job
      #
      #
      # @return [SidekiqUniqueJobs::Lock::WhileExecuting] an instance of a lock
      #
      def runtime_lock
        @runtime_lock ||= SidekiqUniqueJobs::Lock::WhileExecuting.new(item, callback, redis_pool)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sidekiq-unique-jobs-7.0.0.beta4 lib/sidekiq_unique_jobs/lock/until_and_while_executing.rb
sidekiq-unique-jobs-7.0.0.beta3 lib/sidekiq_unique_jobs/lock/until_and_while_executing.rb
sidekiq-unique-jobs-7.0.0.beta2 lib/sidekiq_unique_jobs/lock/until_and_while_executing.rb