Sha256: 20e0f67c2094bde2b9469e24162fb947e3ed74d5ba79456e35a7b1c9166b2804

Contents?: true

Size: 986 Bytes

Versions: 6

Compression:

Stored size: 986 Bytes

Contents

# frozen_string_literal: true

module SidekiqUniqueJobs
  class Lock
    # Locks jobs until the server is done executing the job
    # - Locks on perform_in or perform_async
    # - Unlocks after yielding to the worker's perform method
    #
    # @author Mikael Henriksson <mikael@mhenrixon.com>
    class UntilExecuted < BaseLock
      #
      # Locks a sidekiq job
      #
      # @note Will call a conflict strategy if lock can't be achieved.
      #
      # @return [String, nil] the locked jid when properly locked, else nil.
      #
      # @yield to the caller when given a block
      #
      def lock
        return lock_failed(origin: :client) unless (token = locksmith.lock)
        return yield token if block_given?

        token
      end

      # Executes in the Sidekiq server process
      # @yield to the worker class perform method
      def execute
        locksmith.execute do
          yield
          unlock_and_callback
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sidekiq-unique-jobs-7.1.6 lib/sidekiq_unique_jobs/lock/until_executed.rb
sidekiq-unique-jobs-7.1.5 lib/sidekiq_unique_jobs/lock/until_executed.rb
sidekiq-unique-jobs-7.1.3 lib/sidekiq_unique_jobs/lock/until_executed.rb
sidekiq-unique-jobs-7.1.2 lib/sidekiq_unique_jobs/lock/until_executed.rb
sidekiq-unique-jobs-7.1.1 lib/sidekiq_unique_jobs/lock/until_executed.rb
sidekiq-unique-jobs-7.1.0 lib/sidekiq_unique_jobs/lock/until_executed.rb