Sha256: c158a19299dc70a7ad0cbbc24ee2489261319ff800b0400a2ca3b51b3885e1f0

Contents?: true

Size: 907 Bytes

Versions: 9

Compression:

Stored size: 907 Bytes

Contents

# frozen_string_literal: true

module SidekiqUniqueJobs
  class Lock
    #
    # UntilExpired locks until the job expires
    #
    # @author Mikael Henriksson <mikael@mhenrixon.com>
    #
    class UntilExpired < UntilExecuted
      #
      # 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(&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(&block)
        locksmith.execute(&block)
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
sidekiq-unique-jobs-7.1.16 lib/sidekiq_unique_jobs/lock/until_expired.rb
sidekiq-unique-jobs-7.1.15 lib/sidekiq_unique_jobs/lock/until_expired.rb
sidekiq-unique-jobs-7.1.14 lib/sidekiq_unique_jobs/lock/until_expired.rb
sidekiq-unique-jobs-7.1.13 lib/sidekiq_unique_jobs/lock/until_expired.rb
sidekiq-unique-jobs-7.1.12 lib/sidekiq_unique_jobs/lock/until_expired.rb
sidekiq-unique-jobs-7.1.11 lib/sidekiq_unique_jobs/lock/until_expired.rb
sidekiq-unique-jobs-7.1.10 lib/sidekiq_unique_jobs/lock/until_expired.rb
sidekiq-unique-jobs-7.1.8 lib/sidekiq_unique_jobs/lock/until_expired.rb
sidekiq-unique-jobs-7.1.7 lib/sidekiq_unique_jobs/lock/until_expired.rb