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. job_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, NilClass
The type of lock for this worker.
-
#locks ⇒ Object
A convenience method for using the configured locks.
-
#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
48 49 50 51 52 |
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 48 def lock_class @lock_class ||= locks.fetch(lock_type.to_sym) do raise UnknownLock, "No implementation for `lock: :#{lock_type}`" end end |
#lock_instance ⇒ Lock::BaseLock
A new lock for this Sidekiq Job
38 39 40 |
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 38 def lock_instance @lock_instance ||= lock_class.new(item, after_unlock_hook, @redis_pool) end |
#lock_type ⇒ Symbol, NilClass
The type of lock for this worker
60 61 62 |
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 60 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 |
#options ⇒ Hash<String, Object>
The default options with any matching keys overridden from worker options
70 71 72 73 74 75 76 |
# File 'lib/sidekiq_unique_jobs/options_with_fallback.rb', line 70 def @options ||= begin opts = .dup opts.merge!() if sidekiq_job_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 |