Class: SidekiqUniqueJobs::PayloadHelper
- Inherits:
-
Object
- Object
- SidekiqUniqueJobs::PayloadHelper
- Defined in:
- lib/sidekiq_unique_jobs/payload_helper.rb
Class Method Summary collapse
- .config ⇒ Object
- .filtered_args(worker_class, unique_args, args) ⇒ Object
- .get_payload(klass, queue, *args) ⇒ Object
- .yield_unique_args(worker_class, args) ⇒ Object
Class Method Details
.config ⇒ Object
3 4 5 |
# File 'lib/sidekiq_unique_jobs/payload_helper.rb', line 3 def self.config SidekiqUniqueJobs.config end |
.filtered_args(worker_class, unique_args, args) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/sidekiq_unique_jobs/payload_helper.rb', line 29 def self.filtered_args(worker_class, unique_args, args) case unique_args when Proc unique_args.call(args) when Symbol if worker_class.respond_to?(unique_args) worker_class.send(unique_args, *args) end else args end end |
.get_payload(klass, queue, *args) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/sidekiq_unique_jobs/payload_helper.rb', line 7 def self.get_payload(klass, queue, *args) unique_on_all_queues = false if config.unique_args_enabled worker_class = klass.constantize args = yield_unique_args(worker_class, *args) unique_on_all_queues = worker_class.['unique_on_all_queues'] end md5_arguments = { class: klass, args: args } md5_arguments[:queue] = queue unless unique_on_all_queues "#{config.unique_prefix}:" \ "#{Digest::MD5.hexdigest(Sidekiq.dump_json(md5_arguments))}" end |
.yield_unique_args(worker_class, args) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/sidekiq_unique_jobs/payload_helper.rb', line 21 def self.yield_unique_args(worker_class, args) unique_args = worker_class.['unique_args'] filtered_args(worker_class, unique_args, args) rescue NameError # fallback to not filtering args when class can't be instantiated args end |