Sha256: 954809b94c5b7d0e1935616938e172d3b08c178c7aea53e6e2243245b8414c0e

Contents?: true

Size: 954 Bytes

Versions: 14

Compression:

Stored size: 954 Bytes

Contents

# frozen_string_literal: true

module SidekiqUniqueJobs
  class Lock
    # Locks jobs until {#execute} starts
    # - Locks on perform_in or perform_async
    # - Unlocks before yielding to the worker's perform method
    #
    # @author Mikael Henriksson <mikael@mhenrixon.com>
    class UntilExecuting < 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.
      #
      def lock(&block)
        unless (token = locksmith.lock)
          reflect(:lock_failed, item)
          call_strategy(origin: :client, &block)

          return
        end

        yield if block

        token
      end

      # Executes in the Sidekiq server process
      # @yield to the worker class perform method
      def execute
        callback_safely if locksmith.unlock
        yield
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
sidekiq-unique-jobs-7.1.21 lib/sidekiq_unique_jobs/lock/until_executing.rb
sidekiq-unique-jobs-7.1.20 lib/sidekiq_unique_jobs/lock/until_executing.rb
sidekiq-unique-jobs-7.1.19 lib/sidekiq_unique_jobs/lock/until_executing.rb
sidekiq-unique-jobs-7.1.18 lib/sidekiq_unique_jobs/lock/until_executing.rb
sidekiq-unique-jobs-7.1.17 lib/sidekiq_unique_jobs/lock/until_executing.rb
sidekiq-unique-jobs-7.1.16 lib/sidekiq_unique_jobs/lock/until_executing.rb
sidekiq-unique-jobs-7.1.15 lib/sidekiq_unique_jobs/lock/until_executing.rb
sidekiq-unique-jobs-7.1.14 lib/sidekiq_unique_jobs/lock/until_executing.rb
sidekiq-unique-jobs-7.1.13 lib/sidekiq_unique_jobs/lock/until_executing.rb
sidekiq-unique-jobs-7.1.12 lib/sidekiq_unique_jobs/lock/until_executing.rb
sidekiq-unique-jobs-7.1.11 lib/sidekiq_unique_jobs/lock/until_executing.rb
sidekiq-unique-jobs-7.1.10 lib/sidekiq_unique_jobs/lock/until_executing.rb
sidekiq-unique-jobs-7.1.8 lib/sidekiq_unique_jobs/lock/until_executing.rb
sidekiq-unique-jobs-7.1.7 lib/sidekiq_unique_jobs/lock/until_executing.rb