Module: SidekiqUniqueJobs::OptionsWithFallback

Included in:
Client::Middleware, Server::Middleware
Defined in:
lib/sidekiq_unique_jobs/options_with_fallback.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
6
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 3

def self.included(base)
  base.class_attribute :lock_cache unless base.respond_to?(:lock_cache)
  base.lock_cache ||= {}
end

Instance Method Details

#lockObject



20
21
22
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 20

def lock
  @lock = lock_class.new(item)
end

#lock_classObject



24
25
26
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 24

def lock_class
  lock_cache[unique_lock.to_sym] ||= "SidekiqUniqueJobs::Lock::#{unique_lock.to_s.classify}".constantize
end

#log_duplicate_payload?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 16

def log_duplicate_payload?
  options[LOG_DUPLICATE_KEY] || item[LOG_DUPLICATE_KEY]
end

#optionsObject



38
39
40
41
42
43
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 38

def options
  @options ||= worker_class.get_sidekiq_options if worker_class.respond_to?(:get_sidekiq_options)
  @options ||= Sidekiq.default_worker_options
  @options ||= {}
  @options &&= @options.stringify_keys
end

#unique_disabled?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 12

def unique_disabled?
  !unique_enabled?
end

#unique_enabled?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 8

def unique_enabled?
  options[UNIQUE_KEY] || item[UNIQUE_KEY]
end

#unique_lockObject



28
29
30
31
32
33
34
35
36
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 28

def unique_lock
  if options.key?(UNIQUE_KEY) && options[UNIQUE_KEY] == true
    warn('unique: true is no longer valid. Please set it to the type of lock required like: ' \
         '`unique: :until_executed`')
    options[UNIQUE_LOCK_KEY] || SidekiqUniqueJobs.default_lock
  else
    options[UNIQUE_KEY] || item[UNIQUE_KEY] || SidekiqUniqueJobs.default_lock
  end
end