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 = @worker_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.
-
#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
36 37 38 |
# File 'lib/sidekiq_unique_jobs/sidekiq_worker_methods.rb', line 36 def after_unlock_hook -> { worker_class.after_unlock if worker_method_defined?(:after_unlock) } end |
#default_worker_options ⇒ Object
56 57 58 |
# File 'lib/sidekiq_unique_jobs/sidekiq_worker_methods.rb', line 56 def Sidekiq. end |
#sidekiq_worker_class? ⇒ true, false
Tests that the
24 25 26 |
# File 'lib/sidekiq_unique_jobs/sidekiq_worker_methods.rb', line 24 def sidekiq_worker_class? worker_method_defined?(:get_sidekiq_options) end |
#worker_class ⇒ Sidekiq::Worker
The Sidekiq::Worker implementation
30 31 32 |
# File 'lib/sidekiq_unique_jobs/sidekiq_worker_methods.rb', line 30 def worker_class @_worker_class ||= worker_class_constantize # rubocop:disable Naming/MemoizedInstanceVariableName end |
#worker_class_constantize(klazz = @worker_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
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/sidekiq_unique_jobs/sidekiq_worker_methods.rb', line 44 def worker_class_constantize(klazz = @worker_class) 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 |
# File 'lib/sidekiq_unique_jobs/sidekiq_worker_methods.rb', line 16 def return {} unless sidekiq_worker_class? worker_class..stringify_keys end |