module SidekiqUniqueJobs

Module with constants to avoid string duplication

@author Mikael Henriksson <mikael@mhenrixon.com>

Contains configuration and utility methods that belongs top level

@author Mikael Henriksson <mikael@mhenrixon.com>

Constants

APARTMENT
ARGS
AT
CHANGELOGS
CLASS
CREATED_AT
DEAD_VERSION
DIGESTS
ERRORS
JID
LIMIT
LIVE_VERSION
LOCK
LOCK_ARGS
LOCK_ARGS_METHOD
LOCK_DIGEST
LOCK_EXPIRATION
LOCK_INFO
LOCK_LIMIT
LOCK_PREFIX
LOCK_TIMEOUT
LOCK_TTL
LOCK_TYPE
ON_CLIENT_CONFLICT
ON_CONFLICT
ON_SERVER_CONFLICT
PAYLOAD
PROCESSES
QUEUE
RETRY
SCHEDULE
TIME
TIMEOUT
TTL
TYPE
ThreadSafeConfig

ThreadSafe config exists to be able to document the config class without errors

UNIQUE
UNIQUE_ACROSS_QUEUES
UNIQUE_ACROSS_WORKERS
UNIQUE_ARGS
UNIQUE_ARGS_METHOD
UNIQUE_DIGEST
UNIQUE_PREFIX
UNIQUE_REAPER
VERSION

@return [String] the current SidekiqUniqueJobs version

WORKER

Public Instance Methods

config() click to toggle source

The current configuration (See: {.configure} on how to configure)

@return [SidekiqUniqueJobs::Config] the gem configuration

# File lib/sidekiq_unique_jobs/sidekiq_unique_jobs.rb, line 19
def config
  @config ||= reset!
end
disable!(&block) click to toggle source

Disable SidekiqUniuqeJobs either temporarily in a block or for good

@return [false] when not given a block @return [true, false] the previous value of enable when given a block

@yieldreturn [void] temporarily disable sidekiq unique jobs while executing a block of code

# File lib/sidekiq_unique_jobs/sidekiq_unique_jobs.rb, line 124
def disable!(&block)
  toggle(false, &block)
end
disabled?() click to toggle source

Checks if the gem has been disabled

@return [true] when config.enabled is false @return [false] when config.enabled is true

# File lib/sidekiq_unique_jobs/sidekiq_unique_jobs.rb, line 144
def disabled?
  !enabled?
end
enable!(&block) click to toggle source

Enable SidekiqUniuqeJobs either temporarily in a block or for good

@return [true] when not given a block @return [true, false] the previous value of enable when given a block

@yieldreturn [void] temporarily enable sidekiq unique jobs while executing a block of code

# File lib/sidekiq_unique_jobs/sidekiq_unique_jobs.rb, line 112
def enable!(&block)
  toggle(true, &block)
end
enabled?() click to toggle source

Checks if the gem has been disabled

@return [true] when config.enabled is true @return [false] when config.enabled is false

# File lib/sidekiq_unique_jobs/sidekiq_unique_jobs.rb, line 134
def enabled?
  config.enabled
end
locks() click to toggle source

The current locks

@return [Hash<Symbol, SidekiqUniqueJobs::BaseLock>] the configured locks

# File lib/sidekiq_unique_jobs/sidekiq_unique_jobs.rb, line 39
def locks
  config.locks
end
logger() click to toggle source

The current logger

@return [Logger] the configured logger

# File lib/sidekiq_unique_jobs/sidekiq_unique_jobs.rb, line 49
def logger
  config.logger
end
logger=(other) click to toggle source

Set a new logger

@param [Logger] other another logger

@return [Logger] the new logger

# File lib/sidekiq_unique_jobs/sidekiq_unique_jobs.rb, line 70
def logger=(other)
  config.logger = other
end
reset!() click to toggle source

Resets configuration to deafult

@return [SidekiqUniqueJobs::Config] a default gem configuration

# File lib/sidekiq_unique_jobs/sidekiq_unique_jobs.rb, line 100
def reset!
  @config = SidekiqUniqueJobs::Config.default
end
strategies() click to toggle source

The current strategies

@return [Hash<Symbol, SidekiqUniqueJobs::Strategy>] the configured locks

# File lib/sidekiq_unique_jobs/sidekiq_unique_jobs.rb, line 29
def strategies
  config.strategies
end
use_config(tmp_config = {}) { || ... } click to toggle source

Temporarily use another configuration and reset to the old config after yielding

@param [Hash] tmp_config the temporary configuration to use

@return [void]

@yield control to the caller

# File lib/sidekiq_unique_jobs/sidekiq_unique_jobs.rb, line 82
def use_config(tmp_config = {})
  raise ::ArgumentError, "#{name}.#{__method__} needs a block" unless block_given?

  old_config = config.to_h
  reset!
  configure(tmp_config)
  yield
ensure
  reset!
  configure(old_config.to_h)
end
version() click to toggle source

The current gem version

@return [String] the current gem version

# File lib/sidekiq_unique_jobs/sidekiq_unique_jobs.rb, line 59
def version
  VERSION
end