Class: SidekiqUniqueJobs::Config

Inherits:
ThreadSafeConfig
  • Object
show all
Defined in:
lib/sidekiq_unique_jobs/config.rb

Overview

Shared class for dealing with gem configuration

rubocop:disable Metrics/ClassLength

Author:

Constant Summary collapse

LOCKS_WHILE_ENQUEUED =

Returns Hash<Symbol, SidekiqUniqueJobs::Lock::BaseLock] all available queued locks.

Returns:

{
  until_executing: SidekiqUniqueJobs::Lock::UntilExecuting,
  while_enqueued: SidekiqUniqueJobs::Lock::UntilExecuting,
}.freeze
LOCKS_FROM_PUSH_TO_PROCESSED =

Returns Hash<Symbol, SidekiqUniqueJobs::Lock::BaseLock] all available fulltime locks.

Returns:

{
  until_completed: SidekiqUniqueJobs::Lock::UntilExecuted,
  until_executed: SidekiqUniqueJobs::Lock::UntilExecuted,
  until_performed: SidekiqUniqueJobs::Lock::UntilExecuted,
  until_processed: SidekiqUniqueJobs::Lock::UntilExecuted,
  until_and_while_executing: SidekiqUniqueJobs::Lock::UntilAndWhileExecuting,
  until_successfully_completed: SidekiqUniqueJobs::Lock::UntilExecuted,
}.freeze
LOCKS_WITHOUT_UNLOCK =

Returns Hash<Symbol, SidekiqUniqueJobs::Lock::BaseLock] all available locks without unlock.

Returns:

{
  until_expired: SidekiqUniqueJobs::Lock::UntilExpired,
}.freeze
LOCKS_WHEN_BUSY =

Returns Hash<Symbol, SidekiqUniqueJobs::Lock::BaseLock] all available runtime/client locks.

Returns:

{
  around_perform: SidekiqUniqueJobs::Lock::WhileExecuting,
  while_busy: SidekiqUniqueJobs::Lock::WhileExecuting,
  while_executing: SidekiqUniqueJobs::Lock::WhileExecuting,
  while_working: SidekiqUniqueJobs::Lock::WhileExecuting,
  while_executing_reject: SidekiqUniqueJobs::Lock::WhileExecutingReject,
}.freeze
LOCKS =

Returns Hash<Symbol, SidekiqUniqueJobs::Lock::BaseLock] all available default locks.

Returns:

LOCKS_WHEN_BUSY.dup
.merge(LOCKS_WHILE_ENQUEUED.dup)
.merge(LOCKS_WITHOUT_UNLOCK.dup)
.merge(LOCKS_FROM_PUSH_TO_PROCESSED.dup)
.freeze
STRATEGIES =

Returns Hash<Symbol, SidekiqUniqueJobs::OnConflict::Strategy] all available default strategies.

Returns:

{
  log: SidekiqUniqueJobs::OnConflict::Log,
  raise: SidekiqUniqueJobs::OnConflict::Raise,
  reject: SidekiqUniqueJobs::OnConflict::Reject,
  replace: SidekiqUniqueJobs::OnConflict::Replace,
  reschedule: SidekiqUniqueJobs::OnConflict::Reschedule,
}.freeze
PREFIX =

Returns by default we use this prefix.

Returns:

  • ('uniquejobs')

    by default we use this prefix

"uniquejobs"
LOCK_TIMEOUT =

Returns by default don’t wait for locks.

Returns:

  • (0)

    by default don’t wait for locks

0
LOCK_TTL =

Returns:

  • (nil)
nil
LOGGER_ENABLED =

Returns by default false (don’t disable logger).

Returns:

  • (true, false)

    by default false (don’t disable logger)

true
ENABLED =

Returns by default the gem is enabled.

Returns:

  • (true)

    by default the gem is enabled

true
DEBUG_LUA =

Returns by default we don’t debug the lua scripts because it is slow.

Returns:

  • (false)

    by default we don’t debug the lua scripts because it is slow

false
MAX_HISTORY =

Returns use a changelog history of 1_000 entries by default.

Returns:

  • (1_000)

    use a changelog history of 1_000 entries by default

1_000
REAPER =

Returns prefer the ruby reaper by default since the lua reaper still has problems.

Returns:

  • (:ruby)

    prefer the ruby reaper by default since the lua reaper still has problems

:ruby
REAPER_COUNT =

Returns reap 1_000 orphaned locks at a time by default.

Returns:

  • (1_000)

    reap 1_000 orphaned locks at a time by default

1_000
REAPER_INTERVAL =

Returns reap locks every 10 minutes.

Returns:

  • (600)

    reap locks every 10 minutes

600
REAPER_TIMEOUT =

Returns stop reaper after 10 seconds.

Returns:

  • (10)

    stop reaper after 10 seconds

10
REAPER_RESURRECTOR_INTERVAL =

Returns check if reaper is dead each 3600 seconds.

Returns:

  • (3600)

    check if reaper is dead each 3600 seconds

3600
REAPER_RESURRECTOR_ENABLED =

Returns enable reaper resurrector.

Returns:

  • (false)

    enable reaper resurrector

false
USE_LOCK_INFO =

Returns while useful it also adds overhead so disable lock_info by default.

Returns:

  • (false)

    while useful it also adds overhead so disable lock_info by default

false
RAISE_ON_CONFIG_ERROR =

Returns by default we don’t raise validation errors for workers.

Returns:

  • (false)

    by default we don’t raise validation errors for workers

false
REDIS_VERSION =

Returns default redis version is only to avoid NoMethodError on nil.

Returns:

  • (0.0.0)

    default redis version is only to avoid NoMethodError on nil

"0.0.0"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.defaultSidekiqUniqueJobs::Config

Returns a default configuration

Examples:

SidekiqUniqueJobs::Config.default => <concurrent/mutable_struct/thread_safe_config SidekiqUniqueJobs::Config {
default_lock_timeout: 0,
default_lock_ttl: nil,
enabled: true,
lock_prefix: "uniquejobs",
logger: #<Sidekiq::Logger:0x00007f81e096b0e0 @level=1 ...>,
locks: {
  around_perform: SidekiqUniqueJobs::Lock::WhileExecuting,
  while_busy: SidekiqUniqueJobs::Lock::WhileExecuting,
  while_executing: SidekiqUniqueJobs::Lock::WhileExecuting,
  while_working: SidekiqUniqueJobs::Lock::WhileExecuting,
  while_executing_reject: SidekiqUniqueJobs::Lock::WhileExecutingReject,
  until_executing: SidekiqUniqueJobs::Lock::UntilExecuting,
  while_enqueued: SidekiqUniqueJobs::Lock::UntilExecuting,
  until_expired: SidekiqUniqueJobs::Lock::UntilExpired,
  until_completed: SidekiqUniqueJobs::Lock::UntilExecuted,
  until_executed: SidekiqUniqueJobs::Lock::UntilExecuted,
  until_performed: SidekiqUniqueJobs::Lock::UntilExecuted,
  until_processed: SidekiqUniqueJobs::Lock::UntilExecuted,
  until_and_while_executing: SidekiqUniqueJobs::Lock::UntilAndWhileExecuting,
  until_successfully_completed: SidekiqUniqueJobs::Lock::UntilExecuted
},
strategies: {
  log: SidekiqUniqueJobs::OnConflict::Log,
  raise: SidekiqUniqueJobs::OnConflict::Raise,
  reject: SidekiqUniqueJobs::OnConflict::Reject,
  replace: SidekiqUniqueJobs::OnConflict::Replace,
  reschedule: SidekiqUniqueJobs::OnConflict::Reschedule
},
debug_lua: false,
max_history: 1000,
reaper:: ruby,
reaper_count: 1000,
lock_info: false,
raise_on_config_error: false,
}>

Returns:



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/sidekiq_unique_jobs/config.rb', line 180

def self.default # rubocop:disable Metrics/MethodLength
  new(
    LOCK_TIMEOUT,
    LOCK_TTL,
    ENABLED,
    PREFIX,
    Sidekiq.logger,
    LOGGER_ENABLED,
    LOCKS,
    STRATEGIES,
    DEBUG_LUA,
    MAX_HISTORY,
    REAPER,
    REAPER_COUNT,
    REAPER_INTERVAL,
    REAPER_TIMEOUT,
    REAPER_RESURRECTOR_INTERVAL,
    REAPER_RESURRECTOR_ENABLED,
    USE_LOCK_INFO,
    RAISE_ON_CONFIG_ERROR,
    REDIS_VERSION,
  )
end

Instance Method Details

#add_lock(name, klass) ⇒ void

This method returns an undefined value.

Adds a lock type to the configuration. It will raise if the lock exists already

Examples:

Add a custom lock

add_lock(:my_lock, CustomLocks::MyLock)

Parameters:

  • name (String, Symbol)

    the name of the lock

  • klass (Class)

    the class describing the lock

Raises:

  • DuplicateLock when the name already exists



280
281
282
283
284
285
286
# File 'lib/sidekiq_unique_jobs/config.rb', line 280

def add_lock(name, klass)
  lock_sym = name.to_sym
  raise DuplicateLock, ":#{name} already defined, please use another name" if locks.key?(lock_sym)

  new_locks = locks.dup.merge(lock_sym => klass).freeze
  self.locks = new_locks
end

#add_strategy(name, klass) ⇒ Object

Adds an on_conflict strategy to the configuration.

Examples:

Add a custom strategy

add_lock(:my_strategy, CustomStrategies::MyStrategy)

Parameters:

  • name (String)

    the name of the custom strategy

  • klass (Class)

    the class describing the strategy

Raises:



299
300
301
302
303
304
305
# File 'lib/sidekiq_unique_jobs/config.rb', line 299

def add_strategy(name, klass)
  strategy_sym = name.to_sym
  raise DuplicateStrategy, ":#{name} already defined, please use another name" if strategies.key?(strategy_sym)

  new_strategies = strategies.dup.merge(strategy_sym => klass).freeze
  self.strategies = new_strategies
end

#class_nameString

Memoized variable to get the class name

Returns:

  • (String)

    name of the class



263
264
265
# File 'lib/sidekiq_unique_jobs/config.rb', line 263

def class_name
  @class_name ||= self.class.name
end

#default_lock_timeoutnil, Integer

Deprecated.

Default Lock Timeout

Returns:

  • (nil, Integer)

    configured value or nil



251
252
253
254
255
# File 'lib/sidekiq_unique_jobs/config.rb', line 251

def default_lock_timeout
  warn "[DEPRECATION] `#{class_name}##{__method__}` is deprecated." \
       " Please use `#{class_name}#lock_timeout` instead."
  lock_timeout
end

#default_lock_timeout=(obj) ⇒ Integer

Deprecated.

Set new value for default_lock_timeout

Parameters:

  • obj (Integer)

    value to set (seconds)

Returns:

  • (Integer)


226
227
228
229
230
# File 'lib/sidekiq_unique_jobs/config.rb', line 226

def default_lock_timeout=(obj)
  warn "[DEPRECATION] `#{class_name}##{__method__}` is deprecated." \
       " Please use `#{class_name}#lock_timeout=` instead."
  self.lock_timeout = obj
end

#default_lock_ttlnil, Integer

Deprecated.

Default lock TTL (Time To Live)

Returns:

  • (nil, Integer)

    configured value or nil



238
239
240
241
242
# File 'lib/sidekiq_unique_jobs/config.rb', line 238

def default_lock_ttl
  warn "[DEPRECATION] `#{class_name}##{__method__}` is deprecated." \
       " Please use `#{class_name}#lock_ttl` instead."
  lock_ttl
end

#default_lock_ttl=(obj) ⇒ <type>

Deprecated.

Set the default_lock_ttl

Parameters:

  • obj (Integer)

    value to set (seconds)

Returns:

  • (<type>)

    <description>



212
213
214
215
216
# File 'lib/sidekiq_unique_jobs/config.rb', line 212

def default_lock_ttl=(obj)
  warn "[DEPRECATION] `#{class_name}##{__method__}` is deprecated." \
       " Please use `#{class_name}#lock_ttl=` instead."
  self.lock_ttl = obj
end

#redis_versionString

The current version of redis

Returns:

  • (String)

    a version string eg. ‘5.0.1`



313
314
315
316
# File 'lib/sidekiq_unique_jobs/config.rb', line 313

def redis_version
  self.current_redis_version = SidekiqUniqueJobs.fetch_redis_version if current_redis_version == REDIS_VERSION
  current_redis_version
end