Class: SidekiqBulkJob::Setter
- Inherits:
-
Object
- Object
- SidekiqBulkJob::Setter
- Defined in:
- lib/sidekiq_bulk_job.rb
Instance Method Summary collapse
-
#initialize(opts) ⇒ Setter
constructor
A new instance of Setter.
- #perform_async(job_class, *args) ⇒ Object
-
#perform_in(interval, job_class, *args) ⇒ Object
(also: #perform_at)
interval
must be a timestamp, numeric or something that acts numeric (like an activesupport time interval). - #set(options) ⇒ Object
Constructor Details
#initialize(opts) ⇒ Setter
Returns a new instance of Setter.
16 17 18 |
# File 'lib/sidekiq_bulk_job.rb', line 16 def initialize(opts) @opts = opts end |
Instance Method Details
#perform_async(job_class, *args) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/sidekiq_bulk_job.rb', line 25 def perform_async(job_class, *args) = SidekiqBulkJob::Utils.symbolize_keys(@opts) if [:at].nil? && [:in].nil? payload = { job_class_name: job_class.to_s, perfrom_args: args, queue: [:queue] || SidekiqBulkJob.queue }.select { |_, value| !value.nil? } SidekiqBulkJob.process payload else perform_in([:at] || [:in], job_class, *args) end end |
#perform_in(interval, job_class, *args) ⇒ Object Also known as: perform_at
interval
must be a timestamp, numeric or something that acts
numeric (like an activesupport time interval).
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/sidekiq_bulk_job.rb', line 41 def perform_in(interval, job_class, *args) int = interval.to_f now = SidekiqBulkJob.time_now ts = (int < 1_000_000_000 ? now + int : int).to_f # Optimization to enqueue something now that is scheduled to go out now or in the past if ts > now.to_f = SidekiqBulkJob::Utils.symbolize_keys(@opts) payload = { job_class_name: job_class.to_s, at: ts, perfrom_args: args, queue: [:queue] || SidekiqBulkJob.queue }.select { |_, value| !value.nil? } SidekiqBulkJob.process payload else perform_async(job_class, *args) end end |
#set(options) ⇒ Object
20 21 22 23 |
# File 'lib/sidekiq_bulk_job.rb', line 20 def set() @opts.merge!() self end |