Module: SidekiqUniqueJobs::OptionsWithFallback
- Included in:
- Lock::WhileExecuting, 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)
Class Method Summary collapse
Instance Method Summary collapse
-
#lock_class ⇒ Class
Returns the corresponding class for the lock_type.
-
#lock_instance ⇒ Lock::BaseLock
A new lock for this Sidekiq Job.
-
#lock_type ⇒ Symbol
The type of lock for this worker.
-
#locks ⇒ Object
A convenience method for using the configured locks.
-
#log_duplicate? ⇒ true, ...
Should duplicate payloads be logged?.
-
#options ⇒ Hash<String, Object>
The default options with any matching keys overridden from worker options.
-
#unique_disabled? ⇒ Boolean
Check if unique has been disabled.
-
#unique_enabled? ⇒ true, false
Check if unique has been enabled.
Class Method Details
.included(base) ⇒ Object
12 13 14 |
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 12 def self.included(base) base.send(:include, SidekiqUniqueJobs::SidekiqWorkerMethods) end |
Instance Method Details
#lock_class ⇒ Class
Returns the corresponding class for the lock_type
57 58 59 60 61 62 63 |
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 57 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_instance ⇒ Lock::BaseLock
A new lock for this Sidekiq Job
47 48 49 |
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 47 def lock_instance @lock_instance ||= lock_class.new(item, after_unlock_hook, @redis_pool) end |
#lock_type ⇒ Symbol
The type of lock for this worker
71 72 73 |
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 71 def lock_type @lock_type ||= [LOCK] || item[LOCK] end |
#locks ⇒ Object
A convenience method for using the configured locks
17 18 19 |
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 17 def locks SidekiqUniqueJobs.locks end |
#log_duplicate? ⇒ true, ...
Should duplicate payloads be logged?
37 38 39 |
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 37 def log_duplicate? [LOG_DUPLICATE] || item[LOG_DUPLICATE] end |
#options ⇒ Hash<String, Object>
The default options with any matching keys overridden from worker options
81 82 83 84 85 86 87 |
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 81 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
28 29 30 |
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 28 def unique_disabled? !unique_enabled? end |
#unique_enabled? ⇒ true, false
Check if unique has been enabled
23 24 25 |
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 23 def unique_enabled? SidekiqUniqueJobs.enabled? && lock_type end |