Module: SidekiqUniqueJobs::OptionsWithFallback
- Included in:
- Client::Middleware, Server::Middleware
- Defined in:
- lib/sidekiq_unique_jobs/options_with_fallback.rb
Overview
Module containing methods shared between client and server middleware
Requires the following methods to be defined in the including class
1. item (required)
2. options (can be nil)
3. worker_class (required, can be anything)
Constant Summary collapse
- LOCKS =
{ until_and_while_executing: SidekiqUniqueJobs::Lock::UntilAndWhileExecuting, until_executed: SidekiqUniqueJobs::Lock::UntilExecuted, until_executing: SidekiqUniqueJobs::Lock::UntilExecuting, until_expired: SidekiqUniqueJobs::Lock::UntilExpired, until_timeout: SidekiqUniqueJobs::Lock::UntilExpired, while_executing: SidekiqUniqueJobs::Lock::WhileExecuting, while_executing_reject: SidekiqUniqueJobs::Lock::WhileExecutingReject, }.freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#lock ⇒ SidekiqUniqueJobs::Lock::BaseLock
Check if we should log duplicate payloads.
-
#lock_class ⇒ SidekiqUniqueJobs::Lock::BaseLock
Check if we should log duplicate payloads.
- #lock_type ⇒ Symbol
-
#log_duplicate_payload? ⇒ Boolean
Check if we should log duplicate payloads.
- #options ⇒ Object
-
#unique_disabled? ⇒ Boolean
Check if unique has been disabled.
-
#unique_enabled? ⇒ true, false
Check if unique has been enabled.
- #unique_type ⇒ Object
Class Method Details
.included(base) ⇒ Object
22 23 24 |
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 22 def self.included(base) base.send(:include, SidekiqUniqueJobs::SidekiqWorkerMethods) end |
Instance Method Details
#lock ⇒ SidekiqUniqueJobs::Lock::BaseLock
Check if we should log duplicate payloads
44 45 46 |
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 44 def lock @lock ||= lock_class.new(item, after_unlock_hook, @redis_pool) end |
#lock_class ⇒ SidekiqUniqueJobs::Lock::BaseLock
Check if we should log duplicate payloads
50 51 52 53 54 55 56 |
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 50 def lock_class @lock_class ||= begin LOCKS.fetch(lock_type.to_sym) do raise UnknownLock, "No implementation for `lock: :#{lock_type}`" end end end |
#lock_type ⇒ Symbol
59 60 61 |
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 59 def lock_type @lock_type ||= item[LOCK_KEY] || [LOCK_KEY] || unique_type end |
#log_duplicate_payload? ⇒ Boolean
Check if we should log duplicate payloads
38 39 40 |
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 38 def log_duplicate_payload? [LOG_DUPLICATE_KEY] || item[LOG_DUPLICATE_KEY] end |
#options ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 67 def @options ||= begin opts = .dup opts.merge!() if sidekiq_worker_class? (opts || {}).stringify_keys end end |
#unique_disabled? ⇒ Boolean
Check if unique has been disabled
33 34 35 |
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 33 def unique_disabled? !unique_enabled? end |
#unique_enabled? ⇒ true, false
Check if unique has been enabled
28 29 30 |
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 28 def unique_enabled? SidekiqUniqueJobs.config.enabled && lock_type end |
#unique_type ⇒ Object
63 64 65 |
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 63 def unique_type [UNIQUE_KEY] || item[UNIQUE_KEY] end |