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

Instance Method Details

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



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/debt_management_center/sidekiq/va_notify_email_job.rb', line 27

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



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/debt_management_center/sidekiq/va_notify_email_job.rb', line 12

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