Module: SidekiqUniqueJobs::SidekiqWorkerMethods
- Included in:
- OnConflict::Reschedule, Timeout::Calculator, UniqueArgs
- Defined in:
- lib/sidekiq_unique_jobs/sidekiq_worker_methods.rb
Overview
Module with convenience methods for the Sidekiq::Worker class
Instance Method Summary collapse
-
#after_unlock_hook ⇒ Proc
The hook to call after a successful unlock.
- #default_worker_options ⇒ Object
-
#sidekiq_worker_class? ⇒ true, false
Tests that the.
-
#worker_class ⇒ Sidekiq::Worker
The Sidekiq::Worker implementation.
-
#worker_class_constantize(klazz) ⇒ Sidekiq::Worker
Attempt to constantize a string worker_class argument, always failing back to the original argument when the constant can’t be found.
-
#worker_method_defined?(method_sym) ⇒ true, false
Avoids duplicating worker_class.respond_to? in multiple places.
-
#worker_options ⇒ Hash
Wraps #get_sidekiq_options to always work with a hash.
Instance Method Details
#after_unlock_hook ⇒ Proc
The hook to call after a successful unlock
37 38 39 |
# File 'lib/sidekiq_unique_jobs/sidekiq_worker_methods.rb', line 37 def after_unlock_hook -> { worker_class.after_unlock if worker_method_defined?(:after_unlock) } end |
#default_worker_options ⇒ Object
59 60 61 |
# File 'lib/sidekiq_unique_jobs/sidekiq_worker_methods.rb', line 59 def Sidekiq. end |
#sidekiq_worker_class? ⇒ true, false
Tests that the
25 26 27 |
# File 'lib/sidekiq_unique_jobs/sidekiq_worker_methods.rb', line 25 def sidekiq_worker_class? worker_method_defined?(:get_sidekiq_options) end |
#worker_class ⇒ Sidekiq::Worker
The Sidekiq::Worker implementation
31 32 33 |
# File 'lib/sidekiq_unique_jobs/sidekiq_worker_methods.rb', line 31 def worker_class @_worker_class ||= worker_class_constantize(@worker_class) # rubocop:disable Naming/MemoizedInstanceVariableName end |
#worker_class_constantize(klazz) ⇒ Sidekiq::Worker
Attempt to constantize a string worker_class argument, always failing back to the original argument when the constant can’t be found
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/sidekiq_unique_jobs/sidekiq_worker_methods.rb', line 45 def worker_class_constantize(klazz) return klazz.class if klazz.is_a?(Sidekiq::Worker) # sidekiq v6.x return klazz unless klazz.is_a?(String) Object.const_get(klazz) rescue NameError => ex case ex. when /uninitialized constant/ klazz else raise end end |
#worker_method_defined?(method_sym) ⇒ true, false
Avoids duplicating worker_class.respond_to? in multiple places
10 11 12 |
# File 'lib/sidekiq_unique_jobs/sidekiq_worker_methods.rb', line 10 def worker_method_defined?(method_sym) worker_class.respond_to?(method_sym) end |
#worker_options ⇒ Hash
Wraps #get_sidekiq_options to always work with a hash
16 17 18 19 20 |
# File 'lib/sidekiq_unique_jobs/sidekiq_worker_methods.rb', line 16 def return {} unless sidekiq_worker_class? worker_class..stringify_keys end |