Module: SidekiqUniqueJobs::OptionsWithFallback

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

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object


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

def self.included(base)
  base.send(:extend, SidekiqUniqueJobs::OptionsWithFallback::ClassMethods)
end

Instance Method Details

#lockObject


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

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

#lock_cacheObject


49
50
51
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 49

def lock_cache
  self.class.lock_cache
end

#lock_cache=(obj) ⇒ Object


53
54
55
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 53

def lock_cache=(obj)
  self.class.lock_cache = obj
end

#lock_classObject


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

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

#lock_typeObject


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

def lock_type
  lock_type_from(options) || lock_type_from(item)
end

#lock_type_from(hash, key = UNIQUE_KEY) ⇒ Object


44
45
46
47
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 44

def lock_type_from(hash, key = UNIQUE_KEY)
  return nil if hash[key].is_a?(TrueClass)
  hash[key]
end

#log_duplicate_payload?Boolean

Returns:

  • (Boolean)

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

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

#optionsObject


57
58
59
60
61
62
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 57

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)

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

def unique_disabled?
  !unique_enabled?
end

#unique_enabled?Boolean

Returns:

  • (Boolean)

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

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

#unique_lockObject


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

def unique_lock
  @unique_lock ||=
    if options.key?(UNIQUE_KEY) && options[UNIQUE_KEY].to_s == '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
      lock_type || SidekiqUniqueJobs.default_lock
    end
end