Sha256: b6918e0d45887dfe052cc0b52c4f912cb9eb1a6ed0ea4286f379996bb8ffee5a

Contents?: true

Size: 1.05 KB

Versions: 22

Compression:

Stored size: 1.05 KB

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
      rescue StandardError => ex
        reflect(:execution_failed, item, ex)
        locksmith.lock(wait: 1)
        raise
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
sidekiq-unique-jobs-8.0.10 lib/sidekiq_unique_jobs/lock/until_executing.rb
sidekiq-unique-jobs-7.1.33 lib/sidekiq_unique_jobs/lock/until_executing.rb
sidekiq-unique-jobs-7.1.32 lib/sidekiq_unique_jobs/lock/until_executing.rb
sidekiq-unique-jobs-8.0.9 lib/sidekiq_unique_jobs/lock/until_executing.rb
sidekiq-unique-jobs-8.0.8 lib/sidekiq_unique_jobs/lock/until_executing.rb
sidekiq-unique-jobs-8.0.7 lib/sidekiq_unique_jobs/lock/until_executing.rb
sidekiq-unique-jobs-8.0.6 lib/sidekiq_unique_jobs/lock/until_executing.rb
sidekiq-unique-jobs-7.1.31 lib/sidekiq_unique_jobs/lock/until_executing.rb
sidekiq-unique-jobs-8.0.5 lib/sidekiq_unique_jobs/lock/until_executing.rb
sidekiq-unique-jobs-8.0.4 lib/sidekiq_unique_jobs/lock/until_executing.rb
sidekiq-unique-jobs-7.1.30 lib/sidekiq_unique_jobs/lock/until_executing.rb
sidekiq-unique-jobs-8.0.3 lib/sidekiq_unique_jobs/lock/until_executing.rb
sidekiq-unique-jobs-8.0.2 lib/sidekiq_unique_jobs/lock/until_executing.rb
sidekiq-unique-jobs-8.0.1 lib/sidekiq_unique_jobs/lock/until_executing.rb
sidekiq-unique-jobs-8.0.0 lib/sidekiq_unique_jobs/lock/until_executing.rb
sidekiq-unique-jobs-7.1.29 lib/sidekiq_unique_jobs/lock/until_executing.rb
sidekiq-unique-jobs-7.1.28 lib/sidekiq_unique_jobs/lock/until_executing.rb
sidekiq-unique-jobs-7.1.27 lib/sidekiq_unique_jobs/lock/until_executing.rb
sidekiq-unique-jobs-7.1.26 lib/sidekiq_unique_jobs/lock/until_executing.rb
sidekiq-unique-jobs-7.1.25 lib/sidekiq_unique_jobs/lock/until_executing.rb