Module: SidekiqUniqueJobs::SidekiqWorkerMethods
- Included in:
- LockArgs, LockDigest, LockTTL, LockTimeout, LockType, OnConflict::Reschedule
- Defined in:
- lib/sidekiq_unique_jobs/sidekiq_worker_methods.rb
Overview
Module with convenience methods for the Sidekiq::Worker class
Instance Attribute Summary collapse
-
#job_class ⇒ Object
Returns the value of attribute job_class.
Instance Method Summary collapse
-
#after_unlock_hook ⇒ Proc
The hook to call after a successful unlock.
-
#default_job_options ⇒ Hash<Symbol, Object>
Returns the default worker options from Sidekiq.
-
#job_class_constantize(klazz = @job_class) ⇒ Sidekiq::Worker
Attempt to constantize a string worker_class argument, always failing back to the original argument when the constant can’t be found.
-
#job_method_defined?(method_sym) ⇒ true, false
Avoids duplicating worker_class.respond_to? in multiple places.
-
#job_options ⇒ Hash
Wraps #get_sidekiq_options to always work with a hash.
-
#sidekiq_job_class? ⇒ true, false
Tests that the.
Instance Attribute Details
#job_class ⇒ Object
Returns the value of attribute job_class.
11 12 13 |
# File 'lib/sidekiq_unique_jobs/sidekiq_worker_methods.rb', line 11 def job_class @job_class end |
Instance Method Details
#after_unlock_hook ⇒ Proc
The hook to call after a successful unlock
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/sidekiq_unique_jobs/sidekiq_worker_methods.rb', line 42 def after_unlock_hook # rubocop:disable Metrics/MethodLength lambda do if @original_job_class.respond_to?(:after_unlock) # instance method in sidekiq v6 if @original_job_class.method(:after_unlock).arity.positive? # arity check to maintain backwards compatibility @original_job_class.after_unlock(item) else @original_job_class.after_unlock end elsif job_class.respond_to?(:after_unlock) # class method regardless of sidekiq version if job_class.method(:after_unlock).arity.positive? # arity check to maintain backwards compatibility job_class.after_unlock(item) else job_class.after_unlock end end end end |
#default_job_options ⇒ Hash<Symbol, Object>
Returns the default worker options from Sidekiq
76 77 78 79 80 81 82 |
# File 'lib/sidekiq_unique_jobs/sidekiq_worker_methods.rb', line 76 def if Sidekiq.respond_to?(:default_job_options) Sidekiq. else Sidekiq. end end |
#job_class_constantize(klazz = @job_class) ⇒ Sidekiq::Worker
Attempt to constantize a string worker_class argument, always failing back to the original argument when the constant can’t be found
66 67 68 |
# File 'lib/sidekiq_unique_jobs/sidekiq_worker_methods.rb', line 66 def job_class_constantize(klazz = @job_class) SidekiqUniqueJobs.safe_constantize(klazz) end |
#job_method_defined?(method_sym) ⇒ true, false
Avoids duplicating worker_class.respond_to? in multiple places
15 16 17 |
# File 'lib/sidekiq_unique_jobs/sidekiq_worker_methods.rb', line 15 def job_method_defined?(method_sym) job_class.respond_to?(method_sym) end |
#job_options ⇒ Hash
Wraps #get_sidekiq_options to always work with a hash
21 22 23 24 25 |
# File 'lib/sidekiq_unique_jobs/sidekiq_worker_methods.rb', line 21 def return {} unless sidekiq_job_class? job_class..deep_stringify_keys end |
#sidekiq_job_class? ⇒ true, false
Tests that the
30 31 32 |
# File 'lib/sidekiq_unique_jobs/sidekiq_worker_methods.rb', line 30 def sidekiq_job_class? job_method_defined?(:get_sidekiq_options) end |