Class: Form526SubmissionFailureEmailJob
- Inherits:
-
Object
- Object
- Form526SubmissionFailureEmailJob
- 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
-
#submission ⇒ Object
Returns the value of attribute submission.
Instance Method Summary collapse
- #form ⇒ Object private
- #list_files_submitted ⇒ Object private
- #list_forms_submitted ⇒ Object private
- #log_failure(error) ⇒ Object private
- #log_success ⇒ Object private
- #parsed_date_of_failure ⇒ Object private
- #perform(submission_id, date_of_failure = Time.now.utc.to_s) ⇒ Object
- #personalisation ⇒ Object private
- #send_email ⇒ Object private
- #track_remedial_action ⇒ Object private
Instance Attribute Details
#submission ⇒ Object
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
#form ⇒ Object (private)
153 154 155 |
# File 'app/sidekiq/form526_submission_failure_email_job.rb', line 153 def form @form ||= submission.form end |
#list_files_submitted ⇒ Object (private)
97 98 99 100 101 102 103 |
# File 'app/sidekiq/form526_submission_failure_email_job.rb', line 97 def list_files_submitted 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_submitted ⇒ Object (private)
88 89 90 91 92 93 94 95 |
# File 'app/sidekiq/form526_submission_failure_email_job.rb', line 88 def list_forms_submitted [].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_success ⇒ Object (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_failure ⇒ Object (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 |
#personalisation ⇒ Object (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: list_forms_submitted.presence || 'None', files_submitted: list_files_submitted.presence || 'None', date_of_failure: parsed_date_of_failure } end |
#send_email ⇒ Object (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_action ⇒ Object (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 |