class SidekiqUniqueJobs::LockConfig


@author Mikael Henriksson <mikael@zoolutions.se>
which helps reduce the amount of instance variables
Gathers all configuration for a lock

def self.from_worker(options)

Returns:
  • (LockConfig) -

Parameters:
  • options (Hash) -- sidekiq_options for worker
def self.from_worker(options)
  new(options.deep_stringify_keys)
end

def errors_as_string

Returns:
  • (String) -
def errors_as_string
  @errors_as_string ||= begin
    error_msg = +"\t"
    error_msg << errors.map { |key, val| "#{key}: :#{val}" }.join("\n\t")
    error_msg
  end
end

def initialize(job_hash = {})

def initialize(job_hash = {})
  @type        = job_hash[LOCK]&.to_sym
  @worker      = job_hash[CLASS]
  @limit       = job_hash.fetch(LOCK_LIMIT) { 1 }
  @timeout     = job_hash.fetch(LOCK_TIMEOUT) { 0 }
  @ttl         = job_hash.fetch(LOCK_TTL) { job_hash.fetch(LOCK_EXPIRATION) { nil } }.to_i
  @pttl        = ttl * 1_000
  @lock_info   = job_hash.fetch(LOCK_INFO) { SidekiqUniqueJobs.config.lock_info }
  @on_conflict = job_hash.fetch(ON_CONFLICT) { nil }
  @errors      = job_hash.fetch(ERRORS) { {} }
  @on_client_conflict = job_hash[ON_CLIENT_CONFLICT]
  @on_server_conflict = job_hash[ON_SERVER_CONFLICT]
end

def on_client_conflict

the strategy to use as conflict resolution from sidekiq client
def on_client_conflict
  @on_client_conflict ||= on_conflict["client"] if on_conflict.is_a?(Hash)
  @on_client_conflict ||= on_conflict
end

def on_server_conflict

the strategy to use as conflict resolution from sidekiq server
def on_server_conflict
  @on_server_conflict ||= on_conflict["server"] if on_conflict.is_a?(Hash)
  @on_server_conflict ||= on_conflict
end

def valid?

Returns:
  • (true, false) -
def valid?
  errors.empty?
end

def wait_for_lock?

Returns:
  • (true, fakse) -
def wait_for_lock?
  timeout.nil? || timeout.positive?
end