Class: CopayNotifications::McpNotificationEmailJob

Inherits:
Object
  • Object
show all
Includes:
SentryLogging, Sidekiq::Job
Defined in:
app/sidekiq/copay_notifications/mcp_notification_email_job.rb

Instance Method Summary collapse

Methods included from SentryLogging

#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger

Instance Method Details

#perform(vet360_id, template_id, backup_email = nil, personalisation = nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/sidekiq/copay_notifications/mcp_notification_email_job.rb', line 17

def perform(vet360_id, template_id, backup_email = nil, personalisation = nil)
  person_resp = VAProfile::ContactInformation::Service.get_person(vet360_id)
  email_address = person_resp.person&.emails&.first&.email_address || backup_email

  if email_address
    StatsD.increment('api.copay_notifications.new_statement.vet_360.success')
    send_email(email_address, template_id, personalisation)
  else
    StatsD.increment('api.copay_notifications.new_statement.vet_360.failure')
    log_exception_to_sentry(CopayNotifications::ProfileMissingEmail.new(vet360_id), {},
                            { error: :mcp_notification_email_job }, 'info')
  end
rescue Common::Exceptions::BackendServiceException => e
  if e.status_code == 400
    args_hash = { args: { template_id:, personalisation: } }
    error_hash = { error: :va_notify_email_job }
    log_exception_to_sentry(e, args_hash, error_hash)
  else
    raise e
  end
end

#send_email(email, template_id, personalisation) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'app/sidekiq/copay_notifications/mcp_notification_email_job.rb', line 39

def send_email(email, template_id, personalisation)
  notify_client = VaNotify::Service.new(Settings.vanotify.services.dmc.api_key)
  notify_client.send_email(
    **{
      email_address: email,
      template_id:,
      personalisation:
    }.compact
  )
end