class SidekiqUniqueJobs::Lock::UntilExecuted

Locks jobs until the server is done executing the job

@author Mikael Henriksson <mikael@mhenrixon.com>

Public Instance Methods

execute() { || ... } click to toggle source

Executes in the Sidekiq server process @yield to the worker class perform method

# File lib/sidekiq_unique_jobs/lock/until_executed.rb, line 35
def execute
  locksmith.execute do
    yield
    unlock_and_callback
  end
end
lock() { || ... } click to toggle source

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

# File lib/sidekiq_unique_jobs/lock/until_executed.rb, line 20
def lock(&block)
  unless (token = locksmith.lock)
    reflect(:lock_failed, item)
    call_strategy(origin: :client, &block)

    return
  end

  yield if block

  token
end