Class: SidekiqUniqueJobs::Lock::WhileExecuting

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

Overview

Locks jobs while the job is executing in the server process

  • Locks before yielding to the worker’s perform method

  • Unlocks after yielding to the worker’s perform method

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

Author:

Direct Known Subclasses

WhileExecutingReject

Instance Method Summary collapse

Methods inherited from BaseLock

#delete, #delete!, #locked?, #unlock

Methods included from SidekiqUniqueJobs::Logging

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

Constructor Details

#initialize(item, callback, redis_pool = nil) ⇒ WhileExecuting

Returns a new instance of WhileExecuting.

Parameters:

  • item (Hash)

    the Sidekiq job hash

  • callback (Proc)

    callback to call after unlock

  • redis_pool (Sidekiq::RedisConnection, ConnectionPool) (defaults to: nil)

    the redis connection



19
20
21
22
# File 'lib/sidekiq_unique_jobs/lock/while_executing.rb', line 19

def initialize(item, callback, redis_pool = nil)
  super(item, callback, redis_pool)
  append_unique_key_suffix
end

Instance Method Details

#execute { ... } ⇒ Object

Executes in the Sidekiq server process.

These jobs are locked in the server process not from the client

Yields:

  • to the worker class perform method



34
35
36
37
38
# File 'lib/sidekiq_unique_jobs/lock/while_executing.rb', line 34

def execute
  return strategy.call unless locksmith.lock(item[LOCK_TIMEOUT_KEY])

  with_cleanup { yield }
end

#locktrue

Simulate that a client lock was achieved.

These locks should only ever be created in the server process.

Returns:

  • (true)

    always returns true



27
28
29
# File 'lib/sidekiq_unique_jobs/lock/while_executing.rb', line 27

def lock
  true
end