Class: Nuntius::TransportDeliveryJob

Inherits:
ApplicationJob show all
Defined in:
app/jobs/nuntius/transport_delivery_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(provider_name, message) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/jobs/nuntius/transport_delivery_job.rb', line 6

def perform(provider_name, message)
  return if message.delivered_or_blocked?
  return if message.parent_message&.delivered_or_blocked?

  if message.provider != provider_name
    original_message = message
    message = message.dup
    message.parent_message = original_message
    message.status = "pending"
    message.provider_id = ""
  end
  message.provider = provider_name
  message.save!

  provider = Nuntius::BaseProvider.class_from_name(provider_name, message.transport).new(message)
  message = provider.deliver
  message.save! unless message.pending?

  # First refresh check is after 5 seconds
  if message.delivered_or_blocked?
    message.cleanup!
  else
    Nuntius::TransportRefreshJob.set(wait: 5).perform_later(provider_name, message) unless Rails.env.development?
  end
end