Class: SidekiqUniqueJobs::Lock::UntilAndWhileExecuting

Inherits:
BaseLock
  • Object
show all
Defined in:
lib/sidekiq_unique_jobs/lock/until_and_while_executing.rb

Overview

Locks jobs while the job is executing in the server process

  • Locks on perform_in or perform_async (see UntilExecuting)

  • Unlocks before yielding to the worker’s perform method (see UntilExecuting)

  • Locks before yielding to the worker’s perform method (see WhileExecuting)

  • Unlocks after yielding to the worker’s perform method (see WhileExecuting)

See BaseLock#lock for more information about the client. See #execute for more information about the server

Author:

Instance Method Summary collapse

Methods inherited from BaseLock

#delete, #delete!, #initialize, #lock, #locked?, #unlock

Methods included from SidekiqUniqueJobs::Logging

#log_debug, #log_error, #log_fatal, #log_info, #log_warn, #logger, #logging_context

Constructor Details

This class inherits a constructor from SidekiqUniqueJobs::Lock::BaseLock

Instance Method Details

#execute { ... } ⇒ Object

Executes in the Sidekiq server process

Yields:

  • to the worker class perform method



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/sidekiq_unique_jobs/lock/until_and_while_executing.rb', line 18

def execute
  if unlock
    lock_on_failure do
      runtime_lock.execute { return yield }
    end
  else
    log_warn "couldn't unlock digest: #{item[UNIQUE_DIGEST_KEY]} #{item[JID_KEY]}"
  end
ensure
  runtime_lock.delete!
end

#runtime_lockObject



30
31
32
# File 'lib/sidekiq_unique_jobs/lock/until_and_while_executing.rb', line 30

def runtime_lock
  @runtime_lock ||= SidekiqUniqueJobs::Lock::WhileExecuting.new(item, callback, redis_pool)
end