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
- #lock ⇒ Object
- #lock_class ⇒ Object
- #lock_type ⇒ Object
- #lock_type_from(hash, key = UNIQUE_KEY) ⇒ Object
- #log_duplicate_payload? ⇒ Boolean
- #options ⇒ Object
- #unique_disabled? ⇒ Boolean
- #unique_enabled? ⇒ Boolean
- #unique_lock ⇒ Object
Class Method Details
.included(base) ⇒ Object
5 6 7 8 |
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 5 def self.included(base) base.class_attribute :lock_cache unless base.respond_to?(:lock_cache) base.lock_cache ||= {} end |
Instance Method Details
#lock ⇒ Object
22 23 24 |
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 22 def lock @lock = lock_class.new(item) end |
#lock_class ⇒ Object
26 27 28 |
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 26 def lock_class lock_cache[unique_lock.to_sym] ||= "SidekiqUniqueJobs::Lock::#{unique_lock.to_s.classify}".constantize end |
#lock_type ⇒ Object
41 42 43 |
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 41 def lock_type lock_type_from() || lock_type_from(item) end |
#lock_type_from(hash, key = UNIQUE_KEY) ⇒ Object
45 46 47 48 |
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 45 def lock_type_from(hash, key = UNIQUE_KEY) return nil if hash[key].is_a?(TrueClass) hash[key] end |
#log_duplicate_payload? ⇒ Boolean
18 19 20 |
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 18 def log_duplicate_payload? [LOG_DUPLICATE_KEY] || item[LOG_DUPLICATE_KEY] end |
#options ⇒ Object
50 51 52 53 54 55 |
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 50 def ||= worker_class. if worker_class.respond_to?(:get_sidekiq_options) ||= Sidekiq. ||= {} &&= .stringify_keys end |
#unique_disabled? ⇒ Boolean
14 15 16 |
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 14 def unique_disabled? !unique_enabled? end |
#unique_enabled? ⇒ Boolean
10 11 12 |
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 10 def unique_enabled? [UNIQUE_KEY] || item[UNIQUE_KEY] end |
#unique_lock ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 30 def unique_lock @unique_lock ||= if .key?(UNIQUE_KEY) && [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`') [UNIQUE_LOCK_KEY] || SidekiqUniqueJobs.default_lock else lock_type || SidekiqUniqueJobs.default_lock end end |