Module: Amigo::QueueBackoffJob::PrependedMethods

Defined in:
lib/amigo/queue_backoff_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(*args) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/amigo/queue_backoff_job.rb', line 127

def perform(*args)
  return super unless ::Amigo::QueueBackoffJob.enabled?
  # rubocop:disable Style/GuardClause, Lint/NonLocalExitFromIterator
  dependent_queues.each do |qname|
    latency = Amigo::QueueBackoffJob.check_latency(qname)
    # If latency is <= 0, we can skip this queue.
    next unless latency.positive?
    # If backoff is nil, ignore this queue and check the next
    # If it's > 0, defer until the future
    # If it's <= 0, run the job and check no more queues
    backoff = calculate_backoff(qname, latency, args)
    next if backoff.nil?
    if backoff.positive?
      self.class.perform_in(backoff, *args)
      return
    else
      return super
    end
  end
  # rubocop:enable Style/GuardClause, Lint/NonLocalExitFromIterator
  super
end