Sha256: 6f442360aa6185734bb146281417b9913c0af5859a801595a4fd181dc0a46f76

Contents?: true

Size: 1.44 KB

Versions: 8

Compression:

Stored size: 1.44 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
          lock_on_failure do
            runtime_lock.execute { return yield }
          end
        else
          log_warn "couldn't unlock digest: #{item[UNIQUE_DIGEST_KEY]} #{item[JID_KEY]}"
        end
      ensure
        runtime_lock.delete!
      end

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

      private

      def lock_on_failure
        yield
        runtime_lock.delete!
      rescue Exception # rubocop:disable Lint/RescueException
        log_error("Failed to execute job, restoring lock")
        lock
        raise
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
sidekiq-unique-jobs-6.0.25 lib/sidekiq_unique_jobs/lock/until_and_while_executing.rb
sidekiq-unique-jobs-6.0.24 lib/sidekiq_unique_jobs/lock/until_and_while_executing.rb
sidekiq-unique-jobs-6.0.23 lib/sidekiq_unique_jobs/lock/until_and_while_executing.rb
sidekiq-unique-jobs-6.0.22 lib/sidekiq_unique_jobs/lock/until_and_while_executing.rb
sidekiq-unique-jobs-6.0.21 lib/sidekiq_unique_jobs/lock/until_and_while_executing.rb
sidekiq-unique-jobs-6.0.20 lib/sidekiq_unique_jobs/lock/until_and_while_executing.rb
sidekiq-unique-jobs-6.0.16 lib/sidekiq_unique_jobs/lock/until_and_while_executing.rb
sidekiq-unique-jobs-6.0.19 lib/sidekiq_unique_jobs/lock/until_and_while_executing.rb