Class: Form526SubmissionFailureEmailJob

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Job
Defined in:
app/sidekiq/form526_submission_failure_email_job.rb

Constant Summary collapse

STATSD_PREFIX =
'api.form_526.veteran_notifications.form526_submission_failure_email'
DD_ZSF_TAGS =
[
  'service:disability-application',
  'function:526_backup_submission_to_lighthouse'
].freeze
FORM_DESCRIPTIONS =
{
  'form4142' => 'VA Form 21-4142',
  'form0781' => 'VA Form 21-0781',
  'form0781a' => 'VA Form 21-0781a',
  'form8940' => 'VA Form 21-8940'
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#submissionObject

Returns the value of attribute submission.



8
9
10
# File 'app/sidekiq/form526_submission_failure_email_job.rb', line 8

def submission
  @submission
end

Instance Method Details

#formObject (private)



153
154
155
# File 'app/sidekiq/form526_submission_failure_email_job.rb', line 153

def form
  @form ||= submission.form
end

#list_files_submittedObject (private)



97
98
99
100
101
102
103
# File 'app/sidekiq/form526_submission_failure_email_job.rb', line 97

def 
  return [] if form['form526_uploads'].blank?

  guids = form['form526_uploads'].map { |data| data&.dig('confirmationCode') }.compact
  files = SupportingEvidenceAttachment.where(guid: guids)
  files.map(&:obscured_filename)
end

#list_forms_submittedObject (private)



88
89
90
91
92
93
94
95
# File 'app/sidekiq/form526_submission_failure_email_job.rb', line 88

def 
  [].tap do |forms|
    forms << FORM_DESCRIPTIONS['form4142'] if form['form4142'].present?
    forms << FORM_DESCRIPTIONS['form0781'] if form['form0781'].present?
    forms << FORM_DESCRIPTIONS['form0781a'] if form.dig('form0781', 'form0781a').present?
    forms << FORM_DESCRIPTIONS['form8940'] if form['form8940'].present?
  end
end

#log_failure(error) ⇒ Object (private)



140
141
142
143
144
145
146
147
148
149
150
151
# File 'app/sidekiq/form526_submission_failure_email_job.rb', line 140

def log_failure(error)
  Rails.logger.error(
    'Form526SubmissionFailureEmailJob notification failed',
    {
      form526_submission_id: submission&.id,
      error_message: error.try(:message),
      timestamp: Time.now.utc
    }
  )

  StatsD.increment("#{STATSD_PREFIX}.error")
end

#log_successObject (private)



127
128
129
130
131
132
133
134
135
136
137
138
# File 'app/sidekiq/form526_submission_failure_email_job.rb', line 127

def log_success
  Rails.logger.info(
    'Form526SubmissionFailureEmailJob notification dispatched',
    {
      form526_submission_id: submission.id,
      timestamp: Time.now.utc
    }
  )

  StatsD.increment("#{STATSD_PREFIX}.success")
  StatsD.increment('silent_failure_avoided_no_confirmation', tags: DD_ZSF_TAGS)
end

#parsed_date_of_failureObject (private)



115
116
117
# File 'app/sidekiq/form526_submission_failure_email_job.rb', line 115

def parsed_date_of_failure
  @date_of_failure.strftime('%B %-d, %Y %-l:%M %P %Z').sub(/([ap])m/, '\1.m.')
end

#perform(submission_id, date_of_failure = Time.now.utc.to_s) ⇒ Object



63
64
65
66
67
68
69
70
71
72
# File 'app/sidekiq/form526_submission_failure_email_job.rb', line 63

def perform(submission_id, date_of_failure = Time.now.utc.to_s)
  @submission = Form526Submission.find(submission_id)
  @date_of_failure = Time.zone.parse(date_of_failure)
  send_email
  track_remedial_action
  log_success
rescue => e
  log_failure(e)
  raise
end

#personalisationObject (private)



105
106
107
108
109
110
111
112
113
# File 'app/sidekiq/form526_submission_failure_email_job.rb', line 105

def personalisation
  {
    first_name: submission.get_first_name,
    date_submitted: submission.format_creation_time_for_mailers,
    forms_submitted: .presence || 'None',
    files_submitted: .presence || 'None',
    date_of_failure: parsed_date_of_failure
  }
end

#send_emailObject (private)



76
77
78
79
80
81
82
83
84
85
86
# File 'app/sidekiq/form526_submission_failure_email_job.rb', line 76

def send_email
  email_client = VaNotify::Service.new(Settings.vanotify.services.benefits_disability.api_key)
  template_id = Settings.vanotify.services.benefits_disability.template_id
                        .form526_submission_failure_notification_template_id

  email_client.send_email(
    email_address: submission.veteran_email_address,
    template_id:,
    personalisation:
  )
end

#track_remedial_actionObject (private)



119
120
121
122
123
124
125
# File 'app/sidekiq/form526_submission_failure_email_job.rb', line 119

def track_remedial_action
  Form526SubmissionRemediation.create!(
    form526_submission: submission,
    remediation_type: Form526SubmissionRemediation.remediation_types['email_notified'],
    lifecycle: ['Email failure notification sent']
  )
end