Class: SidekiqUniqueJobs::Lock::BaseLock Abstract

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
SidekiqUniqueJobs::Logging, Reflectable
Defined in:
lib/sidekiq_unique_jobs/lock/base_lock.rb

Overview

This class is abstract.

Abstract base class for locks

Author:

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Reflectable

#reflect

Methods included from SidekiqUniqueJobs::Logging

#build_message, included, #log_debug, #log_error, #log_fatal, #log_info, #log_warn, #logger, #logging_context, #with_configured_loggers_context, #with_logging_context

Constructor Details

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

Returns a new instance of BaseLock.

Parameters:

  • item (Hash)

    the Sidekiq job hash

  • callback (Proc)

    the callback to use after unlock

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

    the redis connection



38
39
40
41
42
43
44
45
# File 'lib/sidekiq_unique_jobs/lock/base_lock.rb', line 38

def initialize(item, callback, redis_pool = nil)
  @item       = item
  @callback   = callback
  @redis_pool = redis_pool
  @attempt    = 0
  prepare_item # Used to ease testing
  @lock_config = LockConfig.new(item)
end

Class Method Details

.validate_options(options = {}) ⇒ void

This method returns an undefined value.

Validates that the sidekiq_options for the worker is valid

Parameters:

  • options (Hash) (defaults to: {})

    the sidekiq_options given to the worker



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

def self.validate_options(options = {})
  Validator.validate(options)
end

Instance Method Details

#executeObject

Execute the job in the Sidekiq server processor

Raises:

  • (NotImplementedError)

    needs to be implemented in child class



62
63
64
# File 'lib/sidekiq_unique_jobs/lock/base_lock.rb', line 62

def execute
  raise NotImplementedError, "##{__method__} needs to be implemented in #{self.class}"
end

#lock { ... } ⇒ String?

Note:

Will call a conflict strategy if lock can’t be achieved.

Locks a sidekiq job

Yields:

  • to the caller when given a block

Returns:

  • (String, nil)

    the locked jid when properly locked, else nil.

Raises:

  • (NotImplementedError)


56
57
58
# File 'lib/sidekiq_unique_jobs/lock/base_lock.rb', line 56

def lock
  raise NotImplementedError, "##{__method__} needs to be implemented in #{self.class}"
end

#locksmithSidekiqUniqueJobs::Locksmith

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The lock manager/client

Returns:



72
73
74
# File 'lib/sidekiq_unique_jobs/lock/base_lock.rb', line 72

def locksmith
  @locksmith ||= SidekiqUniqueJobs::Locksmith.new(item, redis_pool)
end