Module: Sidekiq::Belt::Community::RunJob
- Defined in:
- lib/sidekiq/belt/community/run_job.rb
Defined Under Namespace
Modules: SidekiqRunJob
Class Method Summary collapse
- .dynamic_type?(arg, type) ⇒ Boolean
- .list_grouped_jobs ⇒ Object
- .run_job(job_id, extra_args = {}) ⇒ Object
- .use! ⇒ Object
Class Method Details
.dynamic_type?(arg, type) ⇒ Boolean
23 24 25 26 27 |
# File 'lib/sidekiq/belt/community/run_job.rb', line 23 def self.dynamic_type?(arg, type) return false unless arg.is_a?(Hash) arg[:dynamic].to_s == type end |
.list_grouped_jobs ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/sidekiq/belt/community/run_job.rb', line 10 def self.list_grouped_jobs jobs = {} Sidekiq::Belt.config.run_jobs.each_with_index do |job, i| job.transform_keys(&:to_sym) job[:id] = i jobs[job[:group].to_s] ||= [] jobs[job[:group].to_s] << job end jobs end |
.run_job(job_id, extra_args = {}) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/sidekiq/belt/community/run_job.rb', line 29 def self.run_job(job_id, extra_args = {}) job = Sidekiq::Belt.config.run_jobs[job_id.to_i] job.transform_keys(&:to_sym) args = job.fetch(:args, []) new_args = [] args.each_with_index do |arg, i| if dynamic_type?(arg, "text") || dynamic_type?(arg, "enum") new_args[i] = extra_args.shift elsif dynamic_type?(arg, "integer") new_args[i] = extra_args.shift.to_i elsif dynamic_type?(arg, "boolean") new_args[i] = extra_args.shift == "true" else new_args << arg end end Module.const_get(job[:class]).perform_async(*new_args) end |