17 lines
519 B
Ruby
17 lines
519 B
Ruby
class DrainOutboundJob < ApplicationJob
|
|
queue_as :mailers
|
|
|
|
def perform
|
|
result = Mailings::OutboundQueue.drain_one!
|
|
return unless result.in?(%i[sent deferred wait])
|
|
return unless Mailings::OutboundQueue.queued_scope.exists?
|
|
|
|
wait = Mailings::OutboundQueue.seconds_until_next_slot
|
|
wait = 0 if wait.blank? || wait.negative?
|
|
max_wait = [ Mailings::OutboundQueue.min_interval.to_f, 2.minutes ].max + 5.seconds
|
|
return if wait > max_wait
|
|
|
|
self.class.set(wait: wait).perform_later
|
|
end
|
|
end
|