Class: SidekiqBulkJob::Setter

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq_bulk_job.rb

Instance Method Summary collapse

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)
  options = SidekiqBulkJob::Utils.symbolize_keys(@opts)
  if options[:at].nil? && options[:in].nil?
    payload = {
        job_class_name: job_class.to_s,
        perfrom_args: args,
        queue: options[:queue] || SidekiqBulkJob.queue
      }.select { |_, value| !value.nil? }
    SidekiqBulkJob.process payload
  else
    perform_in(options[:at] || options[: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
    options = SidekiqBulkJob::Utils.symbolize_keys(@opts)
    payload = {
      job_class_name: job_class.to_s,
      at: ts,
      perfrom_args: args,
      queue: options[: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(options)
  @opts.merge!(options)
  self
end