Module: SidekiqUniqueJobs

Defined in:
lib/sidekiq-unique-jobs.rb,
lib/sidekiq_unique_jobs/cli.rb,
lib/sidekiq_unique_jobs/lock.rb,
lib/sidekiq_unique_jobs/util.rb,
lib/sidekiq_unique_jobs/config.rb,
lib/sidekiq_unique_jobs/scripts.rb,
lib/sidekiq_unique_jobs/testing.rb,
lib/sidekiq_unique_jobs/version.rb,
lib/sidekiq_unique_jobs/constants.rb,
lib/sidekiq_unique_jobs/middleware.rb,
lib/sidekiq_unique_jobs/normalizer.rb,
lib/sidekiq_unique_jobs/unlockable.rb,
lib/sidekiq_unique_jobs/script_mock.rb,
lib/sidekiq_unique_jobs/unique_args.rb,
lib/sidekiq_unique_jobs/client/middleware.rb,
lib/sidekiq_unique_jobs/server/middleware.rb,
lib/sidekiq_unique_jobs/lock/until_timeout.rb,
lib/sidekiq_unique_jobs/timeout_calculator.rb,
lib/sidekiq_unique_jobs/lock/until_executed.rb,
lib/sidekiq_unique_jobs/lock/until_executing.rb,
lib/sidekiq_unique_jobs/lock/while_executing.rb,
lib/sidekiq_unique_jobs/scripts/acquire_lock.rb,
lib/sidekiq_unique_jobs/scripts/release_lock.rb,
lib/sidekiq_unique_jobs/options_with_fallback.rb,
lib/sidekiq_unique_jobs/lock/until_and_while_executing.rb

Defined Under Namespace

Modules: Client, Lock, Middleware, Normalizer, OptionsWithFallback, ScriptMock, Scripts, Server, Unlockable, Util Classes: Cli, Config, QueueLockTimeoutCalculator, RunLockTimeoutCalculator, Testing, TimeoutCalculator, UniqueArgs

Constant Summary collapse

ScriptError =
Class.new(StandardError)
UniqueKeyMissing =
Class.new(ArgumentError)
JidMissing =
Class.new(ArgumentError)
MaxLockTimeMissing =
Class.new(ArgumentError)
UnexpectedValue =
Class.new(StandardError)
VERSION =
'5.0.11'
RunLockFailed =
Class.new(StandardError)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.configObject


25
26
27
28
29
30
31
32
33
34
# File 'lib/sidekiq-unique-jobs.rb', line 25

def config
  @config ||= Config.new(
    unique_prefix: 'uniquejobs',
    default_queue_lock_expiration: 30 * 60,
    default_run_lock_expiration: 60,
    default_lock: :while_executing,
    redis_test_mode: :redis, # :mock
    raise_unique_args_errors: false,
  )
end

.configure(options = {}) ⇒ Object


44
45
46
47
48
49
50
51
52
# File 'lib/sidekiq-unique-jobs.rb', line 44

def configure(options = {})
  if block_given?
    yield config
  else
    options.each do |key, val|
      config.send("#{key}=", val)
    end
  end
end

.connection(redis_pool = nil) ⇒ Object


82
83
84
85
86
87
88
# File 'lib/sidekiq-unique-jobs.rb', line 82

def connection(redis_pool = nil)
  if redis_pool
    redis_pool.with { |conn| yield conn }
  else
    Sidekiq.redis { |conn| yield conn }
  end
end

.default_lockObject


40
41
42
# File 'lib/sidekiq-unique-jobs.rb', line 40

def default_lock
  config.default_lock
end

.loggerObject


36
37
38
# File 'lib/sidekiq-unique-jobs.rb', line 36

def logger
  Sidekiq.logger
end

.mocked?Boolean

Returns:

  • (Boolean)

74
75
76
# File 'lib/sidekiq-unique-jobs.rb', line 74

def mocked?
  config.redis_test_mode == :mock
end

.namespaceObject


54
55
56
# File 'lib/sidekiq-unique-jobs.rb', line 54

def namespace
  @namespace ||= connection { |conn| conn.respond_to?(:namespace) ? conn.namespace : nil }
end

.redis_versionObject


78
79
80
# File 'lib/sidekiq-unique-jobs.rb', line 78

def redis_version
  @redis_version ||= connection { |conn| conn.info('server')['redis_version'] }
end

.synchronize(item, redis_pool) ⇒ Object


90
91
92
# File 'lib/sidekiq-unique-jobs.rb', line 90

def synchronize(item, redis_pool)
  Lock::WhileExecuting.synchronize(item, redis_pool) { yield }
end

.worker_class_constantize(worker_class) ⇒ Object

Attempt to constantize a string worker_class argument, always failing back to the original argument when the constant can't be found

raises an error for other errors


62
63
64
65
66
67
68
69
70
71
72
# File 'lib/sidekiq-unique-jobs.rb', line 62

def worker_class_constantize(worker_class)
  return worker_class unless worker_class.is_a?(String)
  Object.const_get(worker_class)
rescue NameError => ex
  case ex.message
  when /uninitialized constant/
    worker_class
  else
    raise
  end
end

Instance Method Details

#redis_versionObject


78
79
80
# File 'lib/sidekiq-unique-jobs.rb', line 78

def redis_version
  @redis_version ||= connection { |conn| conn.info('server')['redis_version'] }
end

#redis_version_realObject


7
8
9
# File 'lib/sidekiq_unique_jobs/testing.rb', line 7

def redis_version
  @redis_version ||= connection { |conn| conn.info('server')['redis_version'] }
end