Sha256: 0fc0aed2985f1b1c677deee21e0f98816d37a587c47d516549db0ce41edf278b

Contents?: true

Size: 1.38 KB

Versions: 12

Compression:

Stored size: 1.38 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@mhenrixon.com>
    class UntilAndWhileExecuting < BaseLock
      # Executes in the Sidekiq server process
      # @yield to the worker class perform method
      def execute
        if unlock
          lock_on_failure do
            runtime_lock.execute { return yield }
          end
        else
          log_warn "couldn't unlock digest: #{item[LOCK_DIGEST]} #{item[JID]}"
        end
      end

      private

      def lock_on_failure
        yield
      rescue Exception # rubocop:disable Lint/RescueException
        log_error("Runtime lock failed to execute job, restoring server lock")
        lock
        raise
      end

      def runtime_lock
        @runtime_lock ||= SidekiqUniqueJobs::Lock::WhileExecuting.new(item, callback, redis_pool)
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
sidekiq-unique-jobs-7.0.7 lib/sidekiq_unique_jobs/lock/until_and_while_executing.rb
sidekiq-unique-jobs-7.0.6 lib/sidekiq_unique_jobs/lock/until_and_while_executing.rb
sidekiq-unique-jobs-7.0.5 lib/sidekiq_unique_jobs/lock/until_and_while_executing.rb
sidekiq-unique-jobs-7.0.4 lib/sidekiq_unique_jobs/lock/until_and_while_executing.rb
sidekiq-unique-jobs-7.0.3 lib/sidekiq_unique_jobs/lock/until_and_while_executing.rb
sidekiq-unique-jobs-7.0.2 lib/sidekiq_unique_jobs/lock/until_and_while_executing.rb
sidekiq-unique-jobs-7.0.1 lib/sidekiq_unique_jobs/lock/until_and_while_executing.rb
sidekiq-unique-jobs-7.0.0 lib/sidekiq_unique_jobs/lock/until_and_while_executing.rb
sidekiq-unique-jobs-7.0.0.beta29 lib/sidekiq_unique_jobs/lock/until_and_while_executing.rb
sidekiq-unique-jobs-7.0.0.beta28 lib/sidekiq_unique_jobs/lock/until_and_while_executing.rb
sidekiq-unique-jobs-7.0.0.beta27 lib/sidekiq_unique_jobs/lock/until_and_while_executing.rb
sidekiq-unique-jobs-7.0.0.beta26 lib/sidekiq_unique_jobs/lock/until_and_while_executing.rb