Class: DebtManagementCenter::VANotifyEmailJob

Inherits:
Object
  • Object
show all
Includes:
SentryLogging, Sidekiq::Job
Defined in:
lib/debt_management_center/sidekiq/va_notify_email_job.rb

Defined Under Namespace

Classes: UnrecognizedIdentifier

Constant Summary collapse

STATS_KEY =
'api.dmc.va_notify_email'

Instance Method Summary collapse

Methods included from SentryLogging

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

Instance Method Details

#email_params(identifier, template_id, personalisation, id_type) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/debt_management_center/sidekiq/va_notify_email_job.rb', line 36

def email_params(identifier, template_id, personalisation, id_type)
  case id_type.downcase
  when 'email'
    {
      email_address: identifier,
      template_id:,
      personalisation:
    }.compact
  when 'icn'
    {
      recipient_identifier: { id_value: identifier, id_type: 'ICN' },
      template_id:,
      personalisation:
    }.compact
  else
    raise UnrecognizedIdentifier, id_type
  end
end

#perform(identifier, template_id, personalisation = nil, id_type = 'email') ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/debt_management_center/sidekiq/va_notify_email_job.rb', line 21

def perform(identifier, template_id, personalisation = nil, id_type = 'email')
  notify_client = VaNotify::Service.new(Settings.vanotify.services.dmc.api_key)
  notify_client.send_email(email_params(identifier, template_id, personalisation, id_type))
  StatsD.increment("#{STATS_KEY}.success")
rescue => e
  StatsD.increment("#{STATS_KEY}.failure")
  log_exception_to_sentry(
    e,
    {
      args: { template_id: }
    },
    { error: :dmc_va_notify_email_job }
  )
end