From 98b5b0d003a4f74596c0bd4e63e0d704f3ff1e0e Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Wed, 9 Oct 2024 08:41:50 -0400 Subject: [PATCH 01/58] Initial 526 form 4142 benefits intake API work Needs lots of work still --- ...ncillary_form4142_status_polling_record.rb | 2 + .../benefits_intake_status_polling_job.rb | 42 ++++++++++ .../central_mail/submit_form4142_job.rb | 7 +- ..._ancillary_form_4142_status_polling_job.rb | 79 +++++++++++++++++++ .../form526_paranoid_success_polling_job.rb | 20 +---- app/sidekiq/form526_status_polling_job.rb | 16 +--- ...cillary_form4142_status_polling_records.rb | 11 +++ ...cillary_form4142_status_polling_records.rb | 7 ++ ...ary_form4142_status_polling_record_spec.rb | 5 ++ 9 files changed, 156 insertions(+), 33 deletions(-) create mode 100644 app/models/form526_ancillary_form4142_status_polling_record.rb create mode 100644 app/sidekiq/benefits_intake_status_polling_job.rb create mode 100644 app/sidekiq/form526_ancillary_form_4142_status_polling_job.rb create mode 100644 db/migrate/20241008150707_create_form526_ancillary_form4142_status_polling_records.rb create mode 100644 spec/factories/form526_ancillary_form4142_status_polling_records.rb create mode 100644 spec/models/form526_ancillary_form4142_status_polling_record_spec.rb diff --git a/app/models/form526_ancillary_form4142_status_polling_record.rb b/app/models/form526_ancillary_form4142_status_polling_record.rb new file mode 100644 index 00000000000..6a7c9c0c994 --- /dev/null +++ b/app/models/form526_ancillary_form4142_status_polling_record.rb @@ -0,0 +1,2 @@ +class Form526AncillaryForm4142StatusPollingRecord < ApplicationRecord +end diff --git a/app/sidekiq/benefits_intake_status_polling_job.rb b/app/sidekiq/benefits_intake_status_polling_job.rb new file mode 100644 index 00000000000..0670fd54442 --- /dev/null +++ b/app/sidekiq/benefits_intake_status_polling_job.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +require 'benefits_intake_service/service' + +class BenefitsIntakeStatusPollingJob + include Sidekiq::Job + sidekiq_options retry: false + + STATS_KEY = 'api.benefits_intake.polled_status' + MAX_BATCH_SIZE = 1000 + attr_reader :max_batch_size + + def initialize(max_batch_size: MAX_BATCH_SIZE) + @max_batch_size = max_batch_size + @total_handled = 0 + end + + def perform + Rails.logger.info('Beginning Form 526 Intake Status polling') + submissions.in_batches(of: max_batch_size) do |batch| + batch_ids = batch.pluck(:backup_submitted_claim_id).flatten + response = api_to_poll.get_bulk_status_of_uploads(batch_ids) + handle_response(response) + end + Rails.logger.info('Form 526 Intake Status polling complete', + total_handled: @total_handled) + rescue => e + Rails.logger.error('Error processing 526 Intake Status batch', + class: self.class.name, message: e.message) + end + + private + + def api_to_poll + @api_to_poll ||= BenefitsIntakeService::Service.new + end + + def submissions + raise NotImplementedError, "Required submissions records method not implimented. Impliment a `#{self.class.name}.submissions` method." + end + +end diff --git a/app/sidekiq/central_mail/submit_form4142_job.rb b/app/sidekiq/central_mail/submit_form4142_job.rb index 75bfe07f575..966ced713ed 100644 --- a/app/sidekiq/central_mail/submit_form4142_job.rb +++ b/app/sidekiq/central_mail/submit_form4142_job.rb @@ -133,7 +133,7 @@ def lighthouse_service def upload_to_lighthouse Rails.logger.info( - 'Successful Form4142 Submission to Lighthouse', + 'Successful Form4142 Upload Intake UUID aquired from Lighthouse', { benefits_intake_uuid: lighthouse_service.uuid, submission_id: @submission_id } ) @@ -145,6 +145,11 @@ def upload_to_lighthouse } lighthouse_service.upload_doc(**payload) + Form526AncillaryForm4142StatusPollingRecord.new(submission_id:,benefits_intake_uuid:) + Rails.logger.info( + 'Successful Form4142 Submission to Lighthouse', + { benefits_intake_uuid: lighthouse_service.uuid, submission_id: @submission_id } + ) end def generate_metadata diff --git a/app/sidekiq/form526_ancillary_form_4142_status_polling_job.rb b/app/sidekiq/form526_ancillary_form_4142_status_polling_job.rb new file mode 100644 index 00000000000..999b713c557 --- /dev/null +++ b/app/sidekiq/form526_ancillary_form_4142_status_polling_job.rb @@ -0,0 +1,79 @@ +# frozen_string_literal: true + +require 'benefits_intake_service/service' + +class Form526AncillaryForm4142StatusPollingJob < BenefitsIntakeStatusPollingJob + + def initialize(max_batch_size: MAX_BATCH_SIZE) + @max_batch_size = max_batch_size + @total_handled = 0 + end + + def perform + Rails.logger.info('Beginning Form 526 Intake Status polling') + submissions.in_batches(of: max_batch_size) do |batch| + batch_ids = batch.pluck(:backup_submitted_claim_id).flatten + response = api_to_poll.get_bulk_status_of_uploads(batch_ids) + handle_response(response) + end + Rails.logger.info('Form 526 Intake Status polling complete', + total_handled: @total_handled) + rescue => e + Rails.logger.error('Error processing 526 Intake Status batch', + class: self.class.name, message: e.message) + end + + private + + def handle_response(response) + response.body['data']&.each do |submission| + status = submission.dig('attributes', 'status') + form_submission = Form526Submission.find_by(backup_submitted_claim_id: submission['id']) + + handle_submission(status, form_submission) + @total_handled += 1 + end + end + + def handle_submission(status, form_submission) + if %w[error expired].include? status + log_result('failure') + form_submission.rejected! + elsif status == 'vbms' + log_result('true_success') + form_submission.accepted! + elsif status == 'success' + log_result('paranoid_success') + form_submission.paranoid_success! + else + Rails.logger.info( + 'Unknown or incomplete status returned from Benefits Intake API for 526 submission', + status:, + submission_id: form_submission.id + ) + end + end + + + def log_details(result) + ::Rails.logger.info({ + form_id: Form526Submission::FORM_4142, + parent_form_id: Form526Submission::FORM_526, + message: 'Form526 Submission, Form4142 polled status result', + submission_id:, + lighthouse_submission: { + id: + } + }) + end + + + def log_result(result) + StatsD.increment("#{STATS_KEY}.526.#{result}") + StatsD.increment("#{STATS_KEY}.4142.#{result}") + log_details(result) + end + + + +end diff --git a/app/sidekiq/form526_paranoid_success_polling_job.rb b/app/sidekiq/form526_paranoid_success_polling_job.rb index 1f7eba24f1e..66a11cb52f8 100644 --- a/app/sidekiq/form526_paranoid_success_polling_job.rb +++ b/app/sidekiq/form526_paranoid_success_polling_job.rb @@ -2,7 +2,7 @@ require 'benefits_intake_service/service' -class Form526ParanoidSuccessPollingJob +class Form526ParanoidSuccessPollingJob < BenefitsIntakeStatusPollingJob include Sidekiq::Job sidekiq_options retry: false @@ -15,26 +15,8 @@ def initialize(max_batch_size: MAX_BATCH_SIZE) @change_totals = {} end - def perform - Rails.logger.info('Beginning Form 526 paranoid_success polling') - submissions.in_batches(of: max_batch_size) do |batch| - batch_ids = batch.pluck(:backup_submitted_claim_id).flatten - response = api_to_poll.get_bulk_status_of_uploads(batch_ids) - handle_response(response) - end - Rails.logger.info('Form 526 paranoid_success polling complete', - total_checked:, change_totals:) - rescue => e - Rails.logger.error('Error processing 526 paranoid_success batch', - class: self.class.name, message: e.message) - end - private - def api_to_poll - @api_to_poll ||= BenefitsIntakeService::Service.new - end - def submissions @submissions ||= Form526Submission.paranoid_success_type end diff --git a/app/sidekiq/form526_status_polling_job.rb b/app/sidekiq/form526_status_polling_job.rb index b57dbf7dc5d..58614412351 100644 --- a/app/sidekiq/form526_status_polling_job.rb +++ b/app/sidekiq/form526_status_polling_job.rb @@ -2,13 +2,7 @@ require 'benefits_intake_service/service' -class Form526StatusPollingJob - include Sidekiq::Job - sidekiq_options retry: false - - STATS_KEY = 'api.benefits_intake.submission_status' - MAX_BATCH_SIZE = 1000 - attr_reader :max_batch_size +class Form526StatusPollingJob < BenefitsIntakeStatusPollingJob def initialize(max_batch_size: MAX_BATCH_SIZE) @max_batch_size = max_batch_size @@ -31,10 +25,6 @@ def perform private - def api_to_poll - @api_to_poll ||= BenefitsIntakeService::Service.new - end - def submissions @submissions ||= Form526Submission.pending_backup end @@ -69,7 +59,7 @@ def handle_submission(status, form_submission) end def log_result(result) - StatsD.increment("#{STATS_KEY}.526.#{result}") - StatsD.increment("#{STATS_KEY}.all_forms.#{result}") + StatsD.increment("#{STATS_KEY}.submission_status.526.#{result}") + StatsD.increment("#{STATS_KEY}.submission_status.all_forms.#{result}") end end diff --git a/db/migrate/20241008150707_create_form526_ancillary_form4142_status_polling_records.rb b/db/migrate/20241008150707_create_form526_ancillary_form4142_status_polling_records.rb new file mode 100644 index 00000000000..075f877d9a6 --- /dev/null +++ b/db/migrate/20241008150707_create_form526_ancillary_form4142_status_polling_records.rb @@ -0,0 +1,11 @@ +class CreateForm526AncillaryForm4142StatusPollingRecords < ActiveRecord::Migration[7.1] + def change + create_table :form526_ancillary_form4142_status_polling_records do |t| + t.string :benefits_intake_uuid + t.integer :submission_id + t.integer :status + + t.timestamps + end + end +end diff --git a/spec/factories/form526_ancillary_form4142_status_polling_records.rb b/spec/factories/form526_ancillary_form4142_status_polling_records.rb new file mode 100644 index 00000000000..6a40718c16e --- /dev/null +++ b/spec/factories/form526_ancillary_form4142_status_polling_records.rb @@ -0,0 +1,7 @@ +FactoryBot.define do + factory :form526_ancillary_form4142_status_polling_record do + benefits_intake_uuid { "MyString" } + submission_id { 1 } + status { 1 } + end +end diff --git a/spec/models/form526_ancillary_form4142_status_polling_record_spec.rb b/spec/models/form526_ancillary_form4142_status_polling_record_spec.rb new file mode 100644 index 00000000000..40f11f58a71 --- /dev/null +++ b/spec/models/form526_ancillary_form4142_status_polling_record_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Form526AncillaryForm4142StatusPollingRecord, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end From 60e5bd24953531c85d33279b88768bc014674e0a Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Wed, 9 Oct 2024 08:46:05 -0400 Subject: [PATCH 02/58] Specing out more --- .../form526_ancillary_form4142_status_polling_record.rb | 3 +++ .../form526_ancillary_form_4142_status_polling_job.rb | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/app/models/form526_ancillary_form4142_status_polling_record.rb b/app/models/form526_ancillary_form4142_status_polling_record.rb index 6a7c9c0c994..c030b5d05c7 100644 --- a/app/models/form526_ancillary_form4142_status_polling_record.rb +++ b/app/models/form526_ancillary_form4142_status_polling_record.rb @@ -1,2 +1,5 @@ class Form526AncillaryForm4142StatusPollingRecord < ApplicationRecord + def needs_polled + + end end diff --git a/app/sidekiq/form526_ancillary_form_4142_status_polling_job.rb b/app/sidekiq/form526_ancillary_form_4142_status_polling_job.rb index 999b713c557..8d9e962b593 100644 --- a/app/sidekiq/form526_ancillary_form_4142_status_polling_job.rb +++ b/app/sidekiq/form526_ancillary_form_4142_status_polling_job.rb @@ -24,6 +24,11 @@ def perform end private + + def submissions + # TODO + # Form526AncillaryForm4142StatusPollingRecord.needs_polled + end def handle_response(response) response.body['data']&.each do |submission| From 4c68bf84ae82c2e0ef65154e85566ea373a1c064 Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Wed, 9 Oct 2024 09:13:37 -0400 Subject: [PATCH 03/58] Rubocop'ing --- ...ncillary_form4142_status_polling_record.rb | 6 ++--- .../benefits_intake_status_polling_job.rb | 4 +-- .../central_mail/submit_form4142_job.rb | 2 +- ..._ancillary_form_4142_status_polling_job.rb | 26 +++++++------------ app/sidekiq/form526_status_polling_job.rb | 1 - ...cillary_form4142_status_polling_records.rb | 4 ++- ...ary_form4142_status_polling_record_spec.rb | 2 ++ 7 files changed, 21 insertions(+), 24 deletions(-) diff --git a/app/models/form526_ancillary_form4142_status_polling_record.rb b/app/models/form526_ancillary_form4142_status_polling_record.rb index c030b5d05c7..6c9e2e5bcc2 100644 --- a/app/models/form526_ancillary_form4142_status_polling_record.rb +++ b/app/models/form526_ancillary_form4142_status_polling_record.rb @@ -1,5 +1,5 @@ -class Form526AncillaryForm4142StatusPollingRecord < ApplicationRecord - def needs_polled +# frozen_string_literal: true - end +class Form526AncillaryForm4142StatusPollingRecord < ApplicationRecord + def needs_polled; end end diff --git a/app/sidekiq/benefits_intake_status_polling_job.rb b/app/sidekiq/benefits_intake_status_polling_job.rb index 0670fd54442..1a85ec08167 100644 --- a/app/sidekiq/benefits_intake_status_polling_job.rb +++ b/app/sidekiq/benefits_intake_status_polling_job.rb @@ -36,7 +36,7 @@ def api_to_poll end def submissions - raise NotImplementedError, "Required submissions records method not implimented. Impliment a `#{self.class.name}.submissions` method." + raise NotImplementedError, + "Required submissions records method not implimented. Impliment a `#{self.class.name}.submissions` method." end - end diff --git a/app/sidekiq/central_mail/submit_form4142_job.rb b/app/sidekiq/central_mail/submit_form4142_job.rb index 966ced713ed..bb2278d4bfa 100644 --- a/app/sidekiq/central_mail/submit_form4142_job.rb +++ b/app/sidekiq/central_mail/submit_form4142_job.rb @@ -145,7 +145,7 @@ def upload_to_lighthouse } lighthouse_service.upload_doc(**payload) - Form526AncillaryForm4142StatusPollingRecord.new(submission_id:,benefits_intake_uuid:) + Form526AncillaryForm4142StatusPollingRecord.new(submission_id:, benefits_intake_uuid:) Rails.logger.info( 'Successful Form4142 Submission to Lighthouse', { benefits_intake_uuid: lighthouse_service.uuid, submission_id: @submission_id } diff --git a/app/sidekiq/form526_ancillary_form_4142_status_polling_job.rb b/app/sidekiq/form526_ancillary_form_4142_status_polling_job.rb index 8d9e962b593..5ed02db6c5b 100644 --- a/app/sidekiq/form526_ancillary_form_4142_status_polling_job.rb +++ b/app/sidekiq/form526_ancillary_form_4142_status_polling_job.rb @@ -3,7 +3,6 @@ require 'benefits_intake_service/service' class Form526AncillaryForm4142StatusPollingJob < BenefitsIntakeStatusPollingJob - def initialize(max_batch_size: MAX_BATCH_SIZE) @max_batch_size = max_batch_size @total_handled = 0 @@ -24,7 +23,7 @@ def perform end private - + def submissions # TODO # Form526AncillaryForm4142StatusPollingRecord.needs_polled @@ -59,26 +58,21 @@ def handle_submission(status, form_submission) end end - - def log_details(result) + def log_details(_result) ::Rails.logger.info({ - form_id: Form526Submission::FORM_4142, - parent_form_id: Form526Submission::FORM_526, - message: 'Form526 Submission, Form4142 polled status result', - submission_id:, - lighthouse_submission: { - id: - } - }) + form_id: Form526Submission::FORM_4142, + parent_form_id: Form526Submission::FORM_526, + message: 'Form526 Submission, Form4142 polled status result', + submission_id:, + lighthouse_submission: { + id: + } + }) end - def log_result(result) StatsD.increment("#{STATS_KEY}.526.#{result}") StatsD.increment("#{STATS_KEY}.4142.#{result}") log_details(result) end - - - end diff --git a/app/sidekiq/form526_status_polling_job.rb b/app/sidekiq/form526_status_polling_job.rb index 58614412351..a1ec69b9d7c 100644 --- a/app/sidekiq/form526_status_polling_job.rb +++ b/app/sidekiq/form526_status_polling_job.rb @@ -3,7 +3,6 @@ require 'benefits_intake_service/service' class Form526StatusPollingJob < BenefitsIntakeStatusPollingJob - def initialize(max_batch_size: MAX_BATCH_SIZE) @max_batch_size = max_batch_size @total_handled = 0 diff --git a/spec/factories/form526_ancillary_form4142_status_polling_records.rb b/spec/factories/form526_ancillary_form4142_status_polling_records.rb index 6a40718c16e..b3f7afe3a1d 100644 --- a/spec/factories/form526_ancillary_form4142_status_polling_records.rb +++ b/spec/factories/form526_ancillary_form4142_status_polling_records.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + FactoryBot.define do factory :form526_ancillary_form4142_status_polling_record do - benefits_intake_uuid { "MyString" } + benefits_intake_uuid { 'MyString' } submission_id { 1 } status { 1 } end diff --git a/spec/models/form526_ancillary_form4142_status_polling_record_spec.rb b/spec/models/form526_ancillary_form4142_status_polling_record_spec.rb index 40f11f58a71..c743f3efb4d 100644 --- a/spec/models/form526_ancillary_form4142_status_polling_record_spec.rb +++ b/spec/models/form526_ancillary_form4142_status_polling_record_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe Form526AncillaryForm4142StatusPollingRecord, type: :model do From a9e2bf2746b59373179aa445fb49d2fb1c980fd3 Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Wed, 9 Oct 2024 09:23:03 -0400 Subject: [PATCH 04/58] Renaming to more generic 4142 class --- ...orm526_ancillary_form4142_status_polling_record.rb | 9 +++++++-- app/sidekiq/central_mail/submit_form4142_job.rb | 2 ++ ...08150707_create_form4142_status_polling_records.rb | 11 +++++++++++ ...rm526_ancillary_form4142_status_polling_records.rb | 11 ----------- 4 files changed, 20 insertions(+), 13 deletions(-) create mode 100644 db/migrate/20241008150707_create_form4142_status_polling_records.rb delete mode 100644 db/migrate/20241008150707_create_form526_ancillary_form4142_status_polling_records.rb diff --git a/app/models/form526_ancillary_form4142_status_polling_record.rb b/app/models/form526_ancillary_form4142_status_polling_record.rb index 6c9e2e5bcc2..b36a44c9b4f 100644 --- a/app/models/form526_ancillary_form4142_status_polling_record.rb +++ b/app/models/form526_ancillary_form4142_status_polling_record.rb @@ -1,5 +1,10 @@ # frozen_string_literal: true -class Form526AncillaryForm4142StatusPollingRecord < ApplicationRecord - def needs_polled; end +class Form4142StatusPollingRecord < ApplicationRecord + + enum :status, {pending: 0, errored: 1, success: 2}, default: :pending + + scope :needs_polled -> {where(status: :pending)} + + end diff --git a/app/sidekiq/central_mail/submit_form4142_job.rb b/app/sidekiq/central_mail/submit_form4142_job.rb index bb2278d4bfa..35d67ac4376 100644 --- a/app/sidekiq/central_mail/submit_form4142_job.rb +++ b/app/sidekiq/central_mail/submit_form4142_job.rb @@ -145,7 +145,9 @@ def upload_to_lighthouse } lighthouse_service.upload_doc(**payload) + Form526AncillaryForm4142StatusPollingRecord.new(submission_id:, benefits_intake_uuid:) + Rails.logger.info( 'Successful Form4142 Submission to Lighthouse', { benefits_intake_uuid: lighthouse_service.uuid, submission_id: @submission_id } diff --git a/db/migrate/20241008150707_create_form4142_status_polling_records.rb b/db/migrate/20241008150707_create_form4142_status_polling_records.rb new file mode 100644 index 00000000000..1119ecb3ab8 --- /dev/null +++ b/db/migrate/20241008150707_create_form4142_status_polling_records.rb @@ -0,0 +1,11 @@ +class CreateForm4142StatusPollingRecord < ActiveRecord::Migration[7.1] + def change + create_table :form4142_status_polling_records do |t| + t.string :benefits_intake_uuid + t.integer :submission_id + t.integer :status + + t.timestamps + end + end +end diff --git a/db/migrate/20241008150707_create_form526_ancillary_form4142_status_polling_records.rb b/db/migrate/20241008150707_create_form526_ancillary_form4142_status_polling_records.rb deleted file mode 100644 index 075f877d9a6..00000000000 --- a/db/migrate/20241008150707_create_form526_ancillary_form4142_status_polling_records.rb +++ /dev/null @@ -1,11 +0,0 @@ -class CreateForm526AncillaryForm4142StatusPollingRecords < ActiveRecord::Migration[7.1] - def change - create_table :form526_ancillary_form4142_status_polling_records do |t| - t.string :benefits_intake_uuid - t.integer :submission_id - t.integer :status - - t.timestamps - end - end -end From e2829efe663233b4c7a04e61d8547d21980db8e3 Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Wed, 9 Oct 2024 09:30:18 -0400 Subject: [PATCH 05/58] Moving around --- app/sidekiq/central_mail/submit_form4142_job.rb | 4 ++-- ..._polling_records.rb => form4142_status_polling_records.rb} | 2 +- ..._record_spec.rb => form4142_status_polling_record_spec.rb} | 0 3 files changed, 3 insertions(+), 3 deletions(-) rename spec/factories/{form526_ancillary_form4142_status_polling_records.rb => form4142_status_polling_records.rb} (69%) rename spec/models/{form526_ancillary_form4142_status_polling_record_spec.rb => form4142_status_polling_record_spec.rb} (100%) diff --git a/app/sidekiq/central_mail/submit_form4142_job.rb b/app/sidekiq/central_mail/submit_form4142_job.rb index 35d67ac4376..e620dc2182e 100644 --- a/app/sidekiq/central_mail/submit_form4142_job.rb +++ b/app/sidekiq/central_mail/submit_form4142_job.rb @@ -146,11 +146,11 @@ def upload_to_lighthouse lighthouse_service.upload_doc(**payload) - Form526AncillaryForm4142StatusPollingRecord.new(submission_id:, benefits_intake_uuid:) + polling_record = Form4142StatusPollingRecord.new(submission_id:, benefits_intake_uuid:) Rails.logger.info( 'Successful Form4142 Submission to Lighthouse', - { benefits_intake_uuid: lighthouse_service.uuid, submission_id: @submission_id } + { benefits_intake_uuid: lighthouse_service.uuid, submission_id: @submission_id, polling_record_id: polling_record.id} ) end diff --git a/spec/factories/form526_ancillary_form4142_status_polling_records.rb b/spec/factories/form4142_status_polling_records.rb similarity index 69% rename from spec/factories/form526_ancillary_form4142_status_polling_records.rb rename to spec/factories/form4142_status_polling_records.rb index b3f7afe3a1d..a90d69bf474 100644 --- a/spec/factories/form526_ancillary_form4142_status_polling_records.rb +++ b/spec/factories/form4142_status_polling_records.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true FactoryBot.define do - factory :form526_ancillary_form4142_status_polling_record do + factory :form4142_status_polling_record do benefits_intake_uuid { 'MyString' } submission_id { 1 } status { 1 } diff --git a/spec/models/form526_ancillary_form4142_status_polling_record_spec.rb b/spec/models/form4142_status_polling_record_spec.rb similarity index 100% rename from spec/models/form526_ancillary_form4142_status_polling_record_spec.rb rename to spec/models/form4142_status_polling_record_spec.rb From 5b28b4593f00a310b5c161d4fb6e3403e951d6b4 Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Wed, 9 Oct 2024 09:31:25 -0400 Subject: [PATCH 06/58] Moving --- ...status_polling_record.rb => form4142_status_polling_record.rb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename app/models/{form526_ancillary_form4142_status_polling_record.rb => form4142_status_polling_record.rb} (100%) diff --git a/app/models/form526_ancillary_form4142_status_polling_record.rb b/app/models/form4142_status_polling_record.rb similarity index 100% rename from app/models/form526_ancillary_form4142_status_polling_record.rb rename to app/models/form4142_status_polling_record.rb From eacb120547289cf8113d392dd2d0fb593ac0f194 Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Wed, 9 Oct 2024 10:00:12 -0400 Subject: [PATCH 07/58] adding some testing they are faling due to error with VCR/filenumber data --- app/models/form4142_status_polling_record.rb | 2 +- app/sidekiq/central_mail/submit_form4142_job.rb | 2 +- ...form526_ancillary_form_4142_status_polling_job.rb | 2 +- ...8150707_create_form4142_status_polling_records.rb | 2 +- .../sidekiq/central_mail/submit_form4142_job_spec.rb | 12 ++++++++++-- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/models/form4142_status_polling_record.rb b/app/models/form4142_status_polling_record.rb index b36a44c9b4f..0b416941130 100644 --- a/app/models/form4142_status_polling_record.rb +++ b/app/models/form4142_status_polling_record.rb @@ -4,7 +4,7 @@ class Form4142StatusPollingRecord < ApplicationRecord enum :status, {pending: 0, errored: 1, success: 2}, default: :pending - scope :needs_polled -> {where(status: :pending)} + scope :needs_polled, -> {where(status: :pending)} end diff --git a/app/sidekiq/central_mail/submit_form4142_job.rb b/app/sidekiq/central_mail/submit_form4142_job.rb index e620dc2182e..9585efa0ae4 100644 --- a/app/sidekiq/central_mail/submit_form4142_job.rb +++ b/app/sidekiq/central_mail/submit_form4142_job.rb @@ -167,7 +167,7 @@ def generate_metadata 'businessLine' => '', 'fileNumber' => filenumber } - +ap metadata SimpleFormsApiSubmission::MetadataValidator .validate(metadata, zip_code_is_us_based: usa_based?) end diff --git a/app/sidekiq/form526_ancillary_form_4142_status_polling_job.rb b/app/sidekiq/form526_ancillary_form_4142_status_polling_job.rb index 5ed02db6c5b..1a61d0cda4c 100644 --- a/app/sidekiq/form526_ancillary_form_4142_status_polling_job.rb +++ b/app/sidekiq/form526_ancillary_form_4142_status_polling_job.rb @@ -26,7 +26,7 @@ def perform def submissions # TODO - # Form526AncillaryForm4142StatusPollingRecord.needs_polled + Form4142StatusPollingRecord.needs_polled end def handle_response(response) diff --git a/db/migrate/20241008150707_create_form4142_status_polling_records.rb b/db/migrate/20241008150707_create_form4142_status_polling_records.rb index 1119ecb3ab8..d890000aaaa 100644 --- a/db/migrate/20241008150707_create_form4142_status_polling_records.rb +++ b/db/migrate/20241008150707_create_form4142_status_polling_records.rb @@ -1,4 +1,4 @@ -class CreateForm4142StatusPollingRecord < ActiveRecord::Migration[7.1] +class CreateForm4142StatusPollingRecords < ActiveRecord::Migration[7.1] def change create_table :form4142_status_polling_records do |t| t.string :benefits_intake_uuid diff --git a/spec/sidekiq/central_mail/submit_form4142_job_spec.rb b/spec/sidekiq/central_mail/submit_form4142_job_spec.rb index 36d7b97c746..f02308f01cf 100644 --- a/spec/sidekiq/central_mail/submit_form4142_job_spec.rb +++ b/spec/sidekiq/central_mail/submit_form4142_job_spec.rb @@ -204,9 +204,17 @@ end.to change(subject.jobs, :size).by(1) end + it 'Creates a form 4142 submission polling record' do + expect do + VCR.use_cassette('lighthouse/benefits_intake/200_lighthouse_intake_upload_location') do + subject.perform_async(submission.id) + described_class.drain + end + end.to change(Form4142StatusPollingRecord.count, :size).by(1) + end + it 'submits successfully' do - skip 'The VCR cassette needs to be changed to contain Lighthouse specific data.' - VCR.use_cassette('central_mail/submit_4142') do + VCR.use_cassette('lighthouse/benefits_intake/200_lighthouse_intake_upload_location') do subject.perform_async(submission.id) jid = subject.jobs.last['jid'] described_class.drain From b08f2f7593fdebc773e6baa8615255814d922098 Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Wed, 9 Oct 2024 11:29:40 -0400 Subject: [PATCH 08/58] rubocop --- app/models/form4142_status_polling_record.rb | 7 ++----- app/sidekiq/central_mail/submit_form4142_job.rb | 7 ++++--- spec/sidekiq/central_mail/submit_form4142_job_spec.rb | 3 +++ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/models/form4142_status_polling_record.rb b/app/models/form4142_status_polling_record.rb index 0b416941130..76397da3028 100644 --- a/app/models/form4142_status_polling_record.rb +++ b/app/models/form4142_status_polling_record.rb @@ -1,10 +1,7 @@ # frozen_string_literal: true class Form4142StatusPollingRecord < ApplicationRecord + enum :status, { pending: 0, errored: 1, success: 2 }, default: :pending - enum :status, {pending: 0, errored: 1, success: 2}, default: :pending - - scope :needs_polled, -> {where(status: :pending)} - - + scope :needs_polled, -> { where(status: :pending) } end diff --git a/app/sidekiq/central_mail/submit_form4142_job.rb b/app/sidekiq/central_mail/submit_form4142_job.rb index 9585efa0ae4..ae40185026c 100644 --- a/app/sidekiq/central_mail/submit_form4142_job.rb +++ b/app/sidekiq/central_mail/submit_form4142_job.rb @@ -147,10 +147,11 @@ def upload_to_lighthouse lighthouse_service.upload_doc(**payload) polling_record = Form4142StatusPollingRecord.new(submission_id:, benefits_intake_uuid:) - + Rails.logger.info( 'Successful Form4142 Submission to Lighthouse', - { benefits_intake_uuid: lighthouse_service.uuid, submission_id: @submission_id, polling_record_id: polling_record.id} + { benefits_intake_uuid: lighthouse_service.uuid, submission_id: @submission_id, + polling_record_id: polling_record.id } ) end @@ -167,7 +168,7 @@ def generate_metadata 'businessLine' => '', 'fileNumber' => filenumber } -ap metadata + Rails.logger.debug metadata SimpleFormsApiSubmission::MetadataValidator .validate(metadata, zip_code_is_us_based: usa_based?) end diff --git a/spec/sidekiq/central_mail/submit_form4142_job_spec.rb b/spec/sidekiq/central_mail/submit_form4142_job_spec.rb index f02308f01cf..0c2d04d6ed0 100644 --- a/spec/sidekiq/central_mail/submit_form4142_job_spec.rb +++ b/spec/sidekiq/central_mail/submit_form4142_job_spec.rb @@ -29,6 +29,9 @@ let(:evss_claim_id) { 123_456_789 } let(:saved_claim) { FactoryBot.create(:va526ez) } + ap user + exit + describe '.perform_async' do let(:form_json) do File.read('spec/support/disability_compensation_form/submissions/with_4142.json') From 6acea926a4f9695887ed63bdcd6cc40bd1a55bd9 Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Wed, 9 Oct 2024 13:59:44 -0400 Subject: [PATCH 09/58] Adding additional testing --- app/models/form4142_status_polling_record.rb | 5 +- .../central_mail/submit_form4142_job.rb | 7 ++- ..._create_form4142_status_polling_records.rb | 1 + db/schema.rb | 62 ++++++++++++++++++- spec/factories/users.rb | 2 +- .../central_mail/submit_form4142_job_spec.rb | 25 +++++--- 6 files changed, 88 insertions(+), 14 deletions(-) diff --git a/app/models/form4142_status_polling_record.rb b/app/models/form4142_status_polling_record.rb index 76397da3028..bbb3d59e70c 100644 --- a/app/models/form4142_status_polling_record.rb +++ b/app/models/form4142_status_polling_record.rb @@ -1,7 +1,10 @@ # frozen_string_literal: true class Form4142StatusPollingRecord < ApplicationRecord + validates :benefits_intake_uuid, presence: true + validates :submission_id, presence: true + enum :status, { pending: 0, errored: 1, success: 2 }, default: :pending - scope :needs_polled, -> { where(status: :pending) } + end diff --git a/app/sidekiq/central_mail/submit_form4142_job.rb b/app/sidekiq/central_mail/submit_form4142_job.rb index ae40185026c..9265c8faff6 100644 --- a/app/sidekiq/central_mail/submit_form4142_job.rb +++ b/app/sidekiq/central_mail/submit_form4142_job.rb @@ -146,7 +146,12 @@ def upload_to_lighthouse lighthouse_service.upload_doc(**payload) - polling_record = Form4142StatusPollingRecord.new(submission_id:, benefits_intake_uuid:) + polling_record = Form4142StatusPollingRecord.new( + submission_id:, + submission_class: Form526Submission.class_name, + benefits_intake_uuid: lighthouse_service.uuid + ) + polling_record.save! Rails.logger.info( 'Successful Form4142 Submission to Lighthouse', diff --git a/db/migrate/20241008150707_create_form4142_status_polling_records.rb b/db/migrate/20241008150707_create_form4142_status_polling_records.rb index d890000aaaa..7028c6c646b 100644 --- a/db/migrate/20241008150707_create_form4142_status_polling_records.rb +++ b/db/migrate/20241008150707_create_form4142_status_polling_records.rb @@ -3,6 +3,7 @@ def change create_table :form4142_status_polling_records do |t| t.string :benefits_intake_uuid t.integer :submission_id + t.string :submission_class t.integer :status t.timestamps diff --git a/db/schema.rb b/db/schema.rb index 793b442c3e0..6862f14ddf0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_09_04_184430) do +ActiveRecord::Schema[7.1].define(version: 2024_10_08_150707) do # These are extensions that must be enabled in order to support this database enable_extension "btree_gin" enable_extension "fuzzystrmatch" @@ -466,6 +466,18 @@ t.index ["sid"], name: "index_covid_vaccine_registry_submissions_on_sid", unique: true end + create_table "credential_adoption_email_records", force: :cascade do |t| + t.string "icn", null: false + t.string "email_address", null: false + t.string "email_template_id", null: false + t.datetime "email_triggered_at", precision: nil + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["email_address"], name: "index_credential_adoption_email_records_on_email_address" + t.index ["email_template_id"], name: "index_credential_adoption_email_records_on_email_template_id" + t.index ["icn"], name: "index_credential_adoption_email_records_on_icn" + end + create_table "deprecated_user_accounts", force: :cascade do |t| t.uuid "user_account_id" t.bigint "user_verification_id" @@ -576,6 +588,16 @@ t.index ["user_uuid"], name: "index_education_stem_automated_decisions_on_user_uuid" end + create_table "email_records", force: :cascade do |t| + t.string "va_notify_id" + t.integer "email_type" + t.integer "email_state" + t.integer "tracked_item_id" + t.string "tracked_item_class" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "evss_claims", id: :serial, force: :cascade do |t| t.integer "evss_id", null: false t.json "data", null: false @@ -652,6 +674,15 @@ t.index ["veteran_icn", "tax_year"], name: "index_form1095_bs_on_veteran_icn_and_tax_year", unique: true end + create_table "form4142_status_polling_records", force: :cascade do |t| + t.string "benefits_intake_uuid" + t.integer "submission_id" + t.string "submission_class" + t.integer "status" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "form526_job_statuses", id: :serial, force: :cascade do |t| t.integer "form526_submission_id", null: false t.string "job_id", null: false @@ -834,6 +865,13 @@ t.index ["user_uuid"], name: "index_in_progress_forms_on_user_uuid" end + create_table "inherited_proof_verified_user_accounts", force: :cascade do |t| + t.uuid "user_account_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["user_account_id"], name: "index_inherited_proof_verified_user_accounts_on_user_account_id", unique: true + end + create_table "intent_to_file_queue_exhaustions", force: :cascade do |t| t.string "veteran_icn", null: false t.string "form_type" @@ -1305,6 +1343,17 @@ t.index ["user_account_id", "form_id"], name: "index_in_progress_reminders_sent_user_account_form_id", unique: true end + create_table "vba_documents_git_items", force: :cascade do |t| + t.string "url", null: false + t.jsonb "git_item" + t.boolean "notified", default: false + t.string "label" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["notified", "label"], name: "index_vba_documents_git_items_on_notified_and_label" + t.index ["url"], name: "index_vba_documents_git_items_on_url", unique: true + end + create_table "vba_documents_monthly_stats", force: :cascade do |t| t.integer "month", null: false t.integer "year", null: false @@ -1334,6 +1383,17 @@ t.index ["status"], name: "index_vba_documents_upload_submissions_on_status" end + create_table "versions", force: :cascade do |t| + t.string "item_type", null: false + t.bigint "item_id", null: false + t.string "event", null: false + t.string "whodunnit" + t.text "object" + t.datetime "created_at", precision: nil + t.text "object_changes" + t.index ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id" + end + create_table "veteran_device_records", force: :cascade do |t| t.bigint "device_id", null: false t.boolean "active", default: true, null: false diff --git a/spec/factories/users.rb b/spec/factories/users.rb index 0c3de5d99b4..d2a9cba68f3 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -22,7 +22,7 @@ verified_at { nil } sec_id { '123498767' } participant_id { Faker::Number.number(digits: 8) } - birls_id { Faker::Number.number(digits: 10) } + birls_id { Faker::Number.number(digits: 9) } icn { '123498767V234859' } mhv_icn { nil } multifactor { false } diff --git a/spec/sidekiq/central_mail/submit_form4142_job_spec.rb b/spec/sidekiq/central_mail/submit_form4142_job_spec.rb index 0c2d04d6ed0..8495feb4204 100644 --- a/spec/sidekiq/central_mail/submit_form4142_job_spec.rb +++ b/spec/sidekiq/central_mail/submit_form4142_job_spec.rb @@ -29,8 +29,6 @@ let(:evss_claim_id) { 123_456_789 } let(:saved_claim) { FactoryBot.create(:va526ez) } - ap user - exit describe '.perform_async' do let(:form_json) do @@ -210,18 +208,25 @@ it 'Creates a form 4142 submission polling record' do expect do VCR.use_cassette('lighthouse/benefits_intake/200_lighthouse_intake_upload_location') do - subject.perform_async(submission.id) - described_class.drain + VCR.use_cassette('lighthouse/benefits_intake/200_lighthouse_intake_upload') do + subject.perform_async(submission.id) + described_class.drain + end end - end.to change(Form4142StatusPollingRecord.count, :size).by(1) + end.to change(Form4142StatusPollingRecord, :count).by(1) + expect(Form4142StatusPollingRecord.last.submission_id).to eq(submission.id) + expect(Form4142StatusPollingRecord.last.status).to eq('pending') + end it 'submits successfully' do VCR.use_cassette('lighthouse/benefits_intake/200_lighthouse_intake_upload_location') do - subject.perform_async(submission.id) - jid = subject.jobs.last['jid'] - described_class.drain - expect(jid).not_to be_empty + VCR.use_cassette('lighthouse/benefits_intake/200_lighthouse_intake_upload') do + subject.perform_async(submission.id) + jid = subject.jobs.last['jid'] + described_class.drain + expect(jid).not_to be_empty + end end end @@ -287,7 +292,7 @@ context 'with a client error' do it 'raises a central mail response error' do skip 'The VCR cassette needs to be changed to contain Lighthouse specific data.' - VCR.use_cassette('central_mail/submit_4142_400') do + VCR.use_cassette('lighthouse/benefits_intake/200_lighthouse_intake_upload') do subject.perform_async(submission.id) expect { described_class.drain }.to raise_error(CentralMail::SubmitForm4142Job::CentralMailResponseError) end From 165d4a6ec4804fb82a41c1f1278d59969d0d2e19 Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Wed, 9 Oct 2024 14:01:08 -0400 Subject: [PATCH 10/58] Remove debug --- app/sidekiq/central_mail/submit_form4142_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/sidekiq/central_mail/submit_form4142_job.rb b/app/sidekiq/central_mail/submit_form4142_job.rb index 9265c8faff6..405918e920a 100644 --- a/app/sidekiq/central_mail/submit_form4142_job.rb +++ b/app/sidekiq/central_mail/submit_form4142_job.rb @@ -173,7 +173,7 @@ def generate_metadata 'businessLine' => '', 'fileNumber' => filenumber } - Rails.logger.debug metadata + SimpleFormsApiSubmission::MetadataValidator .validate(metadata, zip_code_is_us_based: usa_based?) end From 67c19f12d066de827e65d11cac51193e599e8a49 Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Wed, 9 Oct 2024 14:34:13 -0400 Subject: [PATCH 11/58] model tests --- ..._ancillary_form_4142_status_polling_job.rb | 2 +- .../form4142_status_polling_records.rb | 1 + .../form4142_status_polling_record_spec.rb | 45 ++++++++++++++++++- 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/app/sidekiq/form526_ancillary_form_4142_status_polling_job.rb b/app/sidekiq/form526_ancillary_form_4142_status_polling_job.rb index 1a61d0cda4c..4726a510556 100644 --- a/app/sidekiq/form526_ancillary_form_4142_status_polling_job.rb +++ b/app/sidekiq/form526_ancillary_form_4142_status_polling_job.rb @@ -26,7 +26,7 @@ def perform def submissions # TODO - Form4142StatusPollingRecord.needs_polled + Form4142StatusPollingRecord.pending end def handle_response(response) diff --git a/spec/factories/form4142_status_polling_records.rb b/spec/factories/form4142_status_polling_records.rb index a90d69bf474..d21dd8a04a8 100644 --- a/spec/factories/form4142_status_polling_records.rb +++ b/spec/factories/form4142_status_polling_records.rb @@ -4,6 +4,7 @@ factory :form4142_status_polling_record do benefits_intake_uuid { 'MyString' } submission_id { 1 } + submission_class { 'Form526Submission'} status { 1 } end end diff --git a/spec/models/form4142_status_polling_record_spec.rb b/spec/models/form4142_status_polling_record_spec.rb index c743f3efb4d..89da215921d 100644 --- a/spec/models/form4142_status_polling_record_spec.rb +++ b/spec/models/form4142_status_polling_record_spec.rb @@ -2,6 +2,47 @@ require 'rails_helper' -RSpec.describe Form526AncillaryForm4142StatusPollingRecord, type: :model do - pending "add some examples to (or delete) #{__FILE__}" +RSpec.describe Form4142StatusPollingRecord, type: :model do + + describe 'successful creation' do + it 'when all attrs provided' do + polling_record = Form4142StatusPollingRecord.new(benefits_intake_uuid: '123', submission_id: 123, submission_class: 'Class') + polling_record.save! + expect(polling_record.status).to eq('pending') + end + end + + describe 'errors' do + it 'when missing submission_id' do + expect do + polling_record = Form4142StatusPollingRecord.new(benefits_intake_uuid: '123') + polling_record.save! + end.to raise_error(ActiveRecord::RecordInvalid) + end + + it 'when missing benefits_intake_uuid' do + expect do + polling_record = Form4142StatusPollingRecord.new(submission_id: 123) + polling_record.save! + end.to raise_error(ActiveRecord::RecordInvalid) + end + + it 'when missing submission_id' do + expect do + polling_record = Form4142StatusPollingRecord.new(benefits_intake_uuid: '123') + polling_record.save! + end.to raise_error(ActiveRecord::RecordInvalid) + end + + it 'when missing both benefits_intake_uuid and submission_id' do + expect do + polling_record = Form4142StatusPollingRecord.new + polling_record.save! + end.to raise_error(ActiveRecord::RecordInvalid) + end + + + + end + end From 9e530c1cb766453954a9bcbd694ae95cbbb34a87 Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Thu, 10 Oct 2024 12:12:53 -0400 Subject: [PATCH 12/58] More tests --- app/models/form4142_status_polling_record.rb | 2 - .../central_mail/submit_form4142_job.rb | 2 +- .../form0781_document_upload_failure_email.rb | 1 - ..._ancillary_form_4142_status_polling_job.rb | 65 +++++++++++-------- .../form4142_status_polling_records.rb | 20 +++++- .../form4142_status_polling_record_spec.rb | 18 ++--- .../central_mail/submit_form4142_job_spec.rb | 8 +-- 7 files changed, 68 insertions(+), 48 deletions(-) diff --git a/app/models/form4142_status_polling_record.rb b/app/models/form4142_status_polling_record.rb index bbb3d59e70c..344d1e0a1e9 100644 --- a/app/models/form4142_status_polling_record.rb +++ b/app/models/form4142_status_polling_record.rb @@ -5,6 +5,4 @@ class Form4142StatusPollingRecord < ApplicationRecord validates :submission_id, presence: true enum :status, { pending: 0, errored: 1, success: 2 }, default: :pending - - end diff --git a/app/sidekiq/central_mail/submit_form4142_job.rb b/app/sidekiq/central_mail/submit_form4142_job.rb index 405918e920a..be25e573431 100644 --- a/app/sidekiq/central_mail/submit_form4142_job.rb +++ b/app/sidekiq/central_mail/submit_form4142_job.rb @@ -147,7 +147,7 @@ def upload_to_lighthouse lighthouse_service.upload_doc(**payload) polling_record = Form4142StatusPollingRecord.new( - submission_id:, + submission_id:, submission_class: Form526Submission.class_name, benefits_intake_uuid: lighthouse_service.uuid ) diff --git a/app/sidekiq/evss/disability_compensation_form/form0781_document_upload_failure_email.rb b/app/sidekiq/evss/disability_compensation_form/form0781_document_upload_failure_email.rb index e8dddf518ca..81d062ef379 100644 --- a/app/sidekiq/evss/disability_compensation_form/form0781_document_upload_failure_email.rb +++ b/app/sidekiq/evss/disability_compensation_form/form0781_document_upload_failure_email.rb @@ -66,7 +66,6 @@ def perform(form526_submission_id) with_tracking('Form0781DocumentUploadFailureEmail', form526_submission.saved_claim_id, form526_submission_id) do notify_client = VaNotify::Service.new(Settings.vanotify.services.benefits_disability.api_key) - email_address = form526_submission.veteran_email_address first_name = form526_submission.get_first_name date_submitted = form526_submission.format_creation_time_for_mailers diff --git a/app/sidekiq/form526_ancillary_form_4142_status_polling_job.rb b/app/sidekiq/form526_ancillary_form_4142_status_polling_job.rb index 4726a510556..415c0d9c700 100644 --- a/app/sidekiq/form526_ancillary_form_4142_status_polling_job.rb +++ b/app/sidekiq/form526_ancillary_form_4142_status_polling_job.rb @@ -11,7 +11,7 @@ def initialize(max_batch_size: MAX_BATCH_SIZE) def perform Rails.logger.info('Beginning Form 526 Intake Status polling') submissions.in_batches(of: max_batch_size) do |batch| - batch_ids = batch.pluck(:backup_submitted_claim_id).flatten + batch_ids = batch.pluck(:benefits_intake_uuid).flatten response = api_to_poll.get_bulk_status_of_uploads(batch_ids) handle_response(response) end @@ -22,57 +22,68 @@ def perform class: self.class.name, message: e.message) end + def self.pending + Form4142StatusPollingRecord.pending + end + + def self.pending_ids + pending.pluck(:benefits_intake_uuid) + end + private def submissions - # TODO Form4142StatusPollingRecord.pending end def handle_response(response) response.body['data']&.each do |submission| status = submission.dig('attributes', 'status') - form_submission = Form526Submission.find_by(backup_submitted_claim_id: submission['id']) - - handle_submission(status, form_submission) + polling_record = Form4142StatusPollingRecord.find_by(benefits_intake_uuid: submission['id']) + handle_submission(status, polling_record, status) @total_handled += 1 end end - def handle_submission(status, form_submission) + def handle_submission(status, polling_record, original_status) if %w[error expired].include? status - log_result('failure') - form_submission.rejected! + polling_record.status = :errored + polling_record.save! + log_result('errored', polling_record, original_status) elsif status == 'vbms' - log_result('true_success') - form_submission.accepted! - elsif status == 'success' - log_result('paranoid_success') - form_submission.paranoid_success! + polling_record.status = :success + polling_record.save! + log_result('success', polling_record, original_status) else Rails.logger.info( 'Unknown or incomplete status returned from Benefits Intake API for 526 submission', status:, - submission_id: form_submission.id + previous_status: original_status, + submission_id: polling_record.submission_id, + lighthouse_submission: { + id: polling_record.benefits_intake_uuid + } ) end end - def log_details(_result) - ::Rails.logger.info({ - form_id: Form526Submission::FORM_4142, - parent_form_id: Form526Submission::FORM_526, - message: 'Form526 Submission, Form4142 polled status result', - submission_id:, - lighthouse_submission: { - id: - } - }) + def log_details(result, polling_record, original_status) + info = { + form_id: Form526Submission::FORM_4142, + parent_form_id: Form526Submission::FORM_526, + message: 'Form526 Submission, Form4142 polled status result', + result:, + previous_status: original_status, + submission_id: polling_record.submission_id, + lighthouse_submission: { + id: polling_record.benefits_intake_uuid + } + } + ::Rails.logger.info(info) end - def log_result(result) - StatsD.increment("#{STATS_KEY}.526.#{result}") + def log_result(result, polling_record, original_status) StatsD.increment("#{STATS_KEY}.4142.#{result}") - log_details(result) + log_details(result, polling_record, original_status) end end diff --git a/spec/factories/form4142_status_polling_records.rb b/spec/factories/form4142_status_polling_records.rb index d21dd8a04a8..605a87bc5d6 100644 --- a/spec/factories/form4142_status_polling_records.rb +++ b/spec/factories/form4142_status_polling_records.rb @@ -4,7 +4,23 @@ factory :form4142_status_polling_record do benefits_intake_uuid { 'MyString' } submission_id { 1 } - submission_class { 'Form526Submission'} - status { 1 } + submission_class { 'Form526Submission' } + status { 0 } + + trait :pending do + status { 0 } + end + + trait :has_vcr_data do + benefits_intake_uuid { '6d8433c1-cd55-4c24-affd-f592287a7572' } + end + + trait :errored do + status { 1 } + end + + trait :success do + status { 2 } + end end end diff --git a/spec/models/form4142_status_polling_record_spec.rb b/spec/models/form4142_status_polling_record_spec.rb index 89da215921d..bfa88a173e1 100644 --- a/spec/models/form4142_status_polling_record_spec.rb +++ b/spec/models/form4142_status_polling_record_spec.rb @@ -3,15 +3,15 @@ require 'rails_helper' RSpec.describe Form4142StatusPollingRecord, type: :model do - describe 'successful creation' do it 'when all attrs provided' do - polling_record = Form4142StatusPollingRecord.new(benefits_intake_uuid: '123', submission_id: 123, submission_class: 'Class') - polling_record.save! - expect(polling_record.status).to eq('pending') + polling_record = Form4142StatusPollingRecord.new(benefits_intake_uuid: '123', submission_id: 123, + submission_class: 'Class') + polling_record.save! + expect(polling_record.status).to eq('pending') end end - + describe 'errors' do it 'when missing submission_id' do expect do @@ -19,7 +19,7 @@ polling_record.save! end.to raise_error(ActiveRecord::RecordInvalid) end - + it 'when missing benefits_intake_uuid' do expect do polling_record = Form4142StatusPollingRecord.new(submission_id: 123) @@ -33,16 +33,12 @@ polling_record.save! end.to raise_error(ActiveRecord::RecordInvalid) end - + it 'when missing both benefits_intake_uuid and submission_id' do expect do polling_record = Form4142StatusPollingRecord.new polling_record.save! end.to raise_error(ActiveRecord::RecordInvalid) end - - - end - end diff --git a/spec/sidekiq/central_mail/submit_form4142_job_spec.rb b/spec/sidekiq/central_mail/submit_form4142_job_spec.rb index 8495feb4204..cb8f8b20455 100644 --- a/spec/sidekiq/central_mail/submit_form4142_job_spec.rb +++ b/spec/sidekiq/central_mail/submit_form4142_job_spec.rb @@ -29,7 +29,6 @@ let(:evss_claim_id) { 123_456_789 } let(:saved_claim) { FactoryBot.create(:va526ez) } - describe '.perform_async' do let(:form_json) do File.read('spec/support/disability_compensation_form/submissions/with_4142.json') @@ -214,9 +213,10 @@ end end end.to change(Form4142StatusPollingRecord, :count).by(1) - expect(Form4142StatusPollingRecord.last.submission_id).to eq(submission.id) - expect(Form4142StatusPollingRecord.last.status).to eq('pending') - + record = Form4142StatusPollingRecord.last + expect(record.submission_id).to eq(submission.id) + expect(record.status).to eq('pending') + expect(record.submission_class).to eq('Form526Submission') end it 'submits successfully' do From f6ae257efe6fbb83b107358f89eb9f96afeb9408 Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Thu, 10 Oct 2024 13:13:55 -0400 Subject: [PATCH 13/58] Rubocop and email and flipper support --- .../central_mail/submit_form4142_job.rb | 33 +++++++------ ..._ancillary_form_4142_status_polling_job.rb | 46 +++++++++++++------ .../form526_paranoid_success_polling_job.rb | 3 +- app/sidekiq/form526_status_polling_job.rb | 5 -- config/features.yml | 8 ++++ lib/periodic_jobs.rb | 3 ++ .../form4142_status_polling_record_spec.rb | 7 --- 7 files changed, 63 insertions(+), 42 deletions(-) diff --git a/app/sidekiq/central_mail/submit_form4142_job.rb b/app/sidekiq/central_mail/submit_form4142_job.rb index be25e573431..71578532903 100644 --- a/app/sidekiq/central_mail/submit_form4142_job.rb +++ b/app/sidekiq/central_mail/submit_form4142_job.rb @@ -9,6 +9,8 @@ # TODO: Update Namespace once we are 100% done with CentralMail here module CentralMail class SubmitForm4142Job < EVSS::DisabilityCompensationForm::Job + POLLING_FLIPPER_KEY = :disability_526_form4142_polling_records + extend Logging::ThirdPartyTransaction::MethodWrapper # this is required to make instance variables available to logs via @@ -131,27 +133,32 @@ def lighthouse_service @lighthouse_service ||= BenefitsIntakeService::Service.new(with_upload_location: true) end + def payload_hash(lighthouse_service_location) + { + upload_url: lighthouse_service_location, + file: { file: @pdf_path, file_name: @pdf_path.split('/').last }, + metadata: generate_metadata.to_json, + attachments: [] + } + end + def upload_to_lighthouse Rails.logger.info( 'Successful Form4142 Upload Intake UUID aquired from Lighthouse', { benefits_intake_uuid: lighthouse_service.uuid, submission_id: @submission_id } ) - payload = { - upload_url: lighthouse_service.location, - file: { file: @pdf_path, file_name: @pdf_path.split('/').last }, - metadata: generate_metadata.to_json, - attachments: [] - } - + payload = payload_hash(lighthouse_service.location) lighthouse_service.upload_doc(**payload) - polling_record = Form4142StatusPollingRecord.new( - submission_id:, - submission_class: Form526Submission.class_name, - benefits_intake_uuid: lighthouse_service.uuid - ) - polling_record.save! + if Flipper.enabled?(POLLING_FLIPPER_KEY) + polling_record = Form4142StatusPollingRecord.new( + submission_id:, + submission_class: Form526Submission.class_name, + benefits_intake_uuid: lighthouse_service.uuid + ) + polling_record.save! + end Rails.logger.info( 'Successful Form4142 Submission to Lighthouse', diff --git a/app/sidekiq/form526_ancillary_form_4142_status_polling_job.rb b/app/sidekiq/form526_ancillary_form_4142_status_polling_job.rb index 415c0d9c700..c144f253d88 100644 --- a/app/sidekiq/form526_ancillary_form_4142_status_polling_job.rb +++ b/app/sidekiq/form526_ancillary_form_4142_status_polling_job.rb @@ -3,12 +3,16 @@ require 'benefits_intake_service/service' class Form526AncillaryForm4142StatusPollingJob < BenefitsIntakeStatusPollingJob - def initialize(max_batch_size: MAX_BATCH_SIZE) - @max_batch_size = max_batch_size - @total_handled = 0 - end + POLLING_FLIPPER_KEY = :disability_526_form4142_polling_records + EMAIL_FLIPPER_KEY = :disability_526_form4142_polling_record_failure_email + OVERAL_4142_MAILER_KEY = :form526_send_4142_failure_notification def perform + unless Flipper.enabled?(POLLING_FLIPPER_KEY) + msg = "#{class_name} disabled via flipper :#{POLLING_FLIPPER_KEY}" + Rails.logger.info(msg) + return true + end Rails.logger.info('Beginning Form 526 Intake Status polling') submissions.in_batches(of: max_batch_size) do |batch| batch_ids = batch.pluck(:benefits_intake_uuid).flatten @@ -30,6 +34,16 @@ def self.pending_ids pending.pluck(:benefits_intake_uuid) end + def send_failure_email!(status, polling_record, original_status) + if Flipper.enabled?(OVERALL_4142_MAILER_KEY) && Flipper.enabled?(EMAIL_FLIPPER_KEY) + EVSS::DisabilityCompensationForm::Form4142DocumentUploadFailureEmail.perform_async(polling_record.submission_id) + else + message = "#{class_name} email disabled via flipper :#{EMAIL_FLIPPER_KEY} or :#{OVERALL_4142_MAILER_KEY}" + log_hash = log_detail_hash(status:, polling_record:, original_status:, message:) + Rails.logger.info(log_hash) + end + end + private def submissions @@ -50,28 +64,26 @@ def handle_submission(status, polling_record, original_status) polling_record.status = :errored polling_record.save! log_result('errored', polling_record, original_status) + send_failure_email!(status, polling_record, original_status) elsif status == 'vbms' polling_record.status = :success polling_record.save! log_result('success', polling_record, original_status) else Rails.logger.info( - 'Unknown or incomplete status returned from Benefits Intake API for 526 submission', - status:, - previous_status: original_status, - submission_id: polling_record.submission_id, - lighthouse_submission: { - id: polling_record.benefits_intake_uuid - } + log_detail_hash(message: 'Unknown or incomplete status returned from Benefits Intake API for 526 submission', + status:, + polling_record:, + original_status:) ) end end - def log_details(result, polling_record, original_status) - info = { + def log_detail_hash(result:, polling_record:, original_status:, message:) + { form_id: Form526Submission::FORM_4142, parent_form_id: Form526Submission::FORM_526, - message: 'Form526 Submission, Form4142 polled status result', + message:, result:, previous_status: original_status, submission_id: polling_record.submission_id, @@ -79,7 +91,11 @@ def log_details(result, polling_record, original_status) id: polling_record.benefits_intake_uuid } } - ::Rails.logger.info(info) + end + + def log_details(result, polling_record, original_status) + ::Rails.logger.info(log_detail_hash(message: 'Form526 Submission, Form4142 polled status result', result:, + polling_record:, original_status:)) end def log_result(result, polling_record, original_status) diff --git a/app/sidekiq/form526_paranoid_success_polling_job.rb b/app/sidekiq/form526_paranoid_success_polling_job.rb index 66a11cb52f8..4c72533b081 100644 --- a/app/sidekiq/form526_paranoid_success_polling_job.rb +++ b/app/sidekiq/form526_paranoid_success_polling_job.rb @@ -10,8 +10,7 @@ class Form526ParanoidSuccessPollingJob < BenefitsIntakeStatusPollingJob attr_reader :max_batch_size, :change_totals, :total_checked def initialize(max_batch_size: MAX_BATCH_SIZE) - @max_batch_size = max_batch_size - @total_checked = 0 + super @change_totals = {} end diff --git a/app/sidekiq/form526_status_polling_job.rb b/app/sidekiq/form526_status_polling_job.rb index a1ec69b9d7c..14db34de401 100644 --- a/app/sidekiq/form526_status_polling_job.rb +++ b/app/sidekiq/form526_status_polling_job.rb @@ -3,11 +3,6 @@ require 'benefits_intake_service/service' class Form526StatusPollingJob < BenefitsIntakeStatusPollingJob - def initialize(max_batch_size: MAX_BATCH_SIZE) - @max_batch_size = max_batch_size - @total_handled = 0 - end - def perform Rails.logger.info('Beginning Form 526 Intake Status polling') submissions.in_batches(of: max_batch_size) do |batch| diff --git a/config/features.yml b/config/features.yml index 0dcbff0dcbb..cbccd9027d3 100644 --- a/config/features.yml +++ b/config/features.yml @@ -417,6 +417,14 @@ features: actor_type: user description: Manage dependent removal from view dependent page enable_in_development: true + disability_526_form4142_polling_records: + actor_type: user + description: enables creation of, and tracking of, sent form 4142 documents, from the 526 flow, to the Lighthouse Benefits Intake API + enable_in_development: true + disability_526_form4142_polling_record_failure_email: + actor_type: user + description: enables failure email when explicit failure is detected downstream + enable_in_development: true disability_526_classifier_new_claims: actor_type: user description: enables sending new 526-ez claims to VRO Contention Classification service for more accurate classification entry. diff --git a/lib/periodic_jobs.rb b/lib/periodic_jobs.rb index 8b9f705bb07..991eb551940 100644 --- a/lib/periodic_jobs.rb +++ b/lib/periodic_jobs.rb @@ -63,6 +63,9 @@ # Update Lighthouse526DocumentUpload statuses according to Lighthouse Benefits Documents service tracking mgr.register('15 * * * *', 'Form526DocumentUploadPollingJob') + # Update Form4142PollingRecord statuses according to Lighthouse Benefits Intake service tracking + mgr.register('15 * * * *', 'Form526AncillaryForm4142StatusPollingJob') + # Updates status of FormSubmissions per call to Lighthouse Benefits Intake API mgr.register('0 3 * * *', 'Form526StatusPollingJob') diff --git a/spec/models/form4142_status_polling_record_spec.rb b/spec/models/form4142_status_polling_record_spec.rb index bfa88a173e1..934e16942c0 100644 --- a/spec/models/form4142_status_polling_record_spec.rb +++ b/spec/models/form4142_status_polling_record_spec.rb @@ -27,13 +27,6 @@ end.to raise_error(ActiveRecord::RecordInvalid) end - it 'when missing submission_id' do - expect do - polling_record = Form4142StatusPollingRecord.new(benefits_intake_uuid: '123') - polling_record.save! - end.to raise_error(ActiveRecord::RecordInvalid) - end - it 'when missing both benefits_intake_uuid and submission_id' do expect do polling_record = Form4142StatusPollingRecord.new From a871cabc3318270bab1319d8495bc34dd58cfb88 Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Thu, 10 Oct 2024 13:15:49 -0400 Subject: [PATCH 14/58] Dont need to add to my change linecount --- .../form0781_document_upload_failure_email.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/sidekiq/evss/disability_compensation_form/form0781_document_upload_failure_email.rb b/app/sidekiq/evss/disability_compensation_form/form0781_document_upload_failure_email.rb index 81d062ef379..8687f24f714 100644 --- a/app/sidekiq/evss/disability_compensation_form/form0781_document_upload_failure_email.rb +++ b/app/sidekiq/evss/disability_compensation_form/form0781_document_upload_failure_email.rb @@ -66,6 +66,7 @@ def perform(form526_submission_id) with_tracking('Form0781DocumentUploadFailureEmail', form526_submission.saved_claim_id, form526_submission_id) do notify_client = VaNotify::Service.new(Settings.vanotify.services.benefits_disability.api_key) + email_address = form526_submission.veteran_email_address first_name = form526_submission.get_first_name date_submitted = form526_submission.format_creation_time_for_mailers From 793a68d737c5e12004a1f421d2d581782d5f79c2 Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Thu, 10 Oct 2024 13:16:38 -0400 Subject: [PATCH 15/58] Remove whitespace --- .../form0781_document_upload_failure_email.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/sidekiq/evss/disability_compensation_form/form0781_document_upload_failure_email.rb b/app/sidekiq/evss/disability_compensation_form/form0781_document_upload_failure_email.rb index 8687f24f714..e8dddf518ca 100644 --- a/app/sidekiq/evss/disability_compensation_form/form0781_document_upload_failure_email.rb +++ b/app/sidekiq/evss/disability_compensation_form/form0781_document_upload_failure_email.rb @@ -66,7 +66,7 @@ def perform(form526_submission_id) with_tracking('Form0781DocumentUploadFailureEmail', form526_submission.saved_claim_id, form526_submission_id) do notify_client = VaNotify::Service.new(Settings.vanotify.services.benefits_disability.api_key) - + email_address = form526_submission.veteran_email_address first_name = form526_submission.get_first_name date_submitted = form526_submission.format_creation_time_for_mailers From d88fc3d1f0ed77f21850bbccb33f2a75171fb443 Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Wed, 16 Oct 2024 10:12:20 -0400 Subject: [PATCH 16/58] Removing my own model, using existing FormSubmission/Form526Submission --- app/models/form4142_status_polling_record.rb | 8 -- app/models/form_submission_attempt.rb | 7 +- .../central_mail/submit_form4142_job.rb | 14 ++- ..._ancillary_form_4142_status_polling_job.rb | 105 ------------------ ..._create_form4142_status_polling_records.rb | 12 -- lib/periodic_jobs.rb | 3 - .../form4142_status_polling_records.rb | 26 ----- .../form4142_status_polling_record_spec.rb | 37 ------ 8 files changed, 15 insertions(+), 197 deletions(-) delete mode 100644 app/models/form4142_status_polling_record.rb delete mode 100644 app/sidekiq/form526_ancillary_form_4142_status_polling_job.rb delete mode 100644 db/migrate/20241008150707_create_form4142_status_polling_records.rb delete mode 100644 spec/factories/form4142_status_polling_records.rb delete mode 100644 spec/models/form4142_status_polling_record_spec.rb diff --git a/app/models/form4142_status_polling_record.rb b/app/models/form4142_status_polling_record.rb deleted file mode 100644 index 344d1e0a1e9..00000000000 --- a/app/models/form4142_status_polling_record.rb +++ /dev/null @@ -1,8 +0,0 @@ -# frozen_string_literal: true - -class Form4142StatusPollingRecord < ApplicationRecord - validates :benefits_intake_uuid, presence: true - validates :submission_id, presence: true - - enum :status, { pending: 0, errored: 1, success: 2 }, default: :pending -end diff --git a/app/models/form_submission_attempt.rb b/app/models/form_submission_attempt.rb index e6647a4c632..32c53295e7d 100644 --- a/app/models/form_submission_attempt.rb +++ b/app/models/form_submission_attempt.rb @@ -31,7 +31,12 @@ class FormSubmissionAttempt < ApplicationRecord benefits_intake_uuid: form_submission&.benefits_intake_uuid, form_type: form_submission&.form_type }) - enqueue_result_email(:error) if Flipper.enabled?(:simple_forms_email_notifications) + is_form526_form4142 = form_type == CentralMail::SubmitForm4142Job::FORM4142_FORMSUBMISSION_TYPE + if Flipper.enabled?(:simple_forms_email_notifications) && !is_form526_form4142 + enqueue_result_email(:error) + elsif Flipper.enabled?(:form526_send_4142_failure_notification) && is_form526_form4142 + EVSS::DisabilityCompensationForm::Form4142DocumentUploadFailureEmail.perform_async(Form526Submission.find_by(saved_claim_id:).id) + end end transitions from: :pending, to: :failure diff --git a/app/sidekiq/central_mail/submit_form4142_job.rb b/app/sidekiq/central_mail/submit_form4142_job.rb index 71578532903..609f90d19da 100644 --- a/app/sidekiq/central_mail/submit_form4142_job.rb +++ b/app/sidekiq/central_mail/submit_form4142_job.rb @@ -11,6 +11,7 @@ module CentralMail class SubmitForm4142Job < EVSS::DisabilityCompensationForm::Job POLLING_FLIPPER_KEY = :disability_526_form4142_polling_records + FORM4142_FORMSUBMISSION_TYPE = "#{Form526Submission::FORM_526}_#{Form526Submission::FORM_4142}" extend Logging::ThirdPartyTransaction::MethodWrapper # this is required to make instance variables available to logs via @@ -152,12 +153,15 @@ def upload_to_lighthouse lighthouse_service.upload_doc(**payload) if Flipper.enabled?(POLLING_FLIPPER_KEY) - polling_record = Form4142StatusPollingRecord.new( - submission_id:, - submission_class: Form526Submission.class_name, - benefits_intake_uuid: lighthouse_service.uuid + form526_submission = Form526Submission.find(@submission_id) + form_submission = FormSubmission.create( + form_type: FORM4142_FORMSUBMISSION_TYPE, # form526_form4142 + benefits_intake_uuid: lighthouse_service.uuid, + form_data: {}, # maybe? + user_account: form526_submission.user_account, + saved_claim: form526_submission.saved_claim ) - polling_record.save! + FormSubmissionAttempt.create(form_submission:) end Rails.logger.info( diff --git a/app/sidekiq/form526_ancillary_form_4142_status_polling_job.rb b/app/sidekiq/form526_ancillary_form_4142_status_polling_job.rb deleted file mode 100644 index c144f253d88..00000000000 --- a/app/sidekiq/form526_ancillary_form_4142_status_polling_job.rb +++ /dev/null @@ -1,105 +0,0 @@ -# frozen_string_literal: true - -require 'benefits_intake_service/service' - -class Form526AncillaryForm4142StatusPollingJob < BenefitsIntakeStatusPollingJob - POLLING_FLIPPER_KEY = :disability_526_form4142_polling_records - EMAIL_FLIPPER_KEY = :disability_526_form4142_polling_record_failure_email - OVERAL_4142_MAILER_KEY = :form526_send_4142_failure_notification - - def perform - unless Flipper.enabled?(POLLING_FLIPPER_KEY) - msg = "#{class_name} disabled via flipper :#{POLLING_FLIPPER_KEY}" - Rails.logger.info(msg) - return true - end - Rails.logger.info('Beginning Form 526 Intake Status polling') - submissions.in_batches(of: max_batch_size) do |batch| - batch_ids = batch.pluck(:benefits_intake_uuid).flatten - response = api_to_poll.get_bulk_status_of_uploads(batch_ids) - handle_response(response) - end - Rails.logger.info('Form 526 Intake Status polling complete', - total_handled: @total_handled) - rescue => e - Rails.logger.error('Error processing 526 Intake Status batch', - class: self.class.name, message: e.message) - end - - def self.pending - Form4142StatusPollingRecord.pending - end - - def self.pending_ids - pending.pluck(:benefits_intake_uuid) - end - - def send_failure_email!(status, polling_record, original_status) - if Flipper.enabled?(OVERALL_4142_MAILER_KEY) && Flipper.enabled?(EMAIL_FLIPPER_KEY) - EVSS::DisabilityCompensationForm::Form4142DocumentUploadFailureEmail.perform_async(polling_record.submission_id) - else - message = "#{class_name} email disabled via flipper :#{EMAIL_FLIPPER_KEY} or :#{OVERALL_4142_MAILER_KEY}" - log_hash = log_detail_hash(status:, polling_record:, original_status:, message:) - Rails.logger.info(log_hash) - end - end - - private - - def submissions - Form4142StatusPollingRecord.pending - end - - def handle_response(response) - response.body['data']&.each do |submission| - status = submission.dig('attributes', 'status') - polling_record = Form4142StatusPollingRecord.find_by(benefits_intake_uuid: submission['id']) - handle_submission(status, polling_record, status) - @total_handled += 1 - end - end - - def handle_submission(status, polling_record, original_status) - if %w[error expired].include? status - polling_record.status = :errored - polling_record.save! - log_result('errored', polling_record, original_status) - send_failure_email!(status, polling_record, original_status) - elsif status == 'vbms' - polling_record.status = :success - polling_record.save! - log_result('success', polling_record, original_status) - else - Rails.logger.info( - log_detail_hash(message: 'Unknown or incomplete status returned from Benefits Intake API for 526 submission', - status:, - polling_record:, - original_status:) - ) - end - end - - def log_detail_hash(result:, polling_record:, original_status:, message:) - { - form_id: Form526Submission::FORM_4142, - parent_form_id: Form526Submission::FORM_526, - message:, - result:, - previous_status: original_status, - submission_id: polling_record.submission_id, - lighthouse_submission: { - id: polling_record.benefits_intake_uuid - } - } - end - - def log_details(result, polling_record, original_status) - ::Rails.logger.info(log_detail_hash(message: 'Form526 Submission, Form4142 polled status result', result:, - polling_record:, original_status:)) - end - - def log_result(result, polling_record, original_status) - StatsD.increment("#{STATS_KEY}.4142.#{result}") - log_details(result, polling_record, original_status) - end -end diff --git a/db/migrate/20241008150707_create_form4142_status_polling_records.rb b/db/migrate/20241008150707_create_form4142_status_polling_records.rb deleted file mode 100644 index 7028c6c646b..00000000000 --- a/db/migrate/20241008150707_create_form4142_status_polling_records.rb +++ /dev/null @@ -1,12 +0,0 @@ -class CreateForm4142StatusPollingRecords < ActiveRecord::Migration[7.1] - def change - create_table :form4142_status_polling_records do |t| - t.string :benefits_intake_uuid - t.integer :submission_id - t.string :submission_class - t.integer :status - - t.timestamps - end - end -end diff --git a/lib/periodic_jobs.rb b/lib/periodic_jobs.rb index 991eb551940..8b9f705bb07 100644 --- a/lib/periodic_jobs.rb +++ b/lib/periodic_jobs.rb @@ -63,9 +63,6 @@ # Update Lighthouse526DocumentUpload statuses according to Lighthouse Benefits Documents service tracking mgr.register('15 * * * *', 'Form526DocumentUploadPollingJob') - # Update Form4142PollingRecord statuses according to Lighthouse Benefits Intake service tracking - mgr.register('15 * * * *', 'Form526AncillaryForm4142StatusPollingJob') - # Updates status of FormSubmissions per call to Lighthouse Benefits Intake API mgr.register('0 3 * * *', 'Form526StatusPollingJob') diff --git a/spec/factories/form4142_status_polling_records.rb b/spec/factories/form4142_status_polling_records.rb deleted file mode 100644 index 605a87bc5d6..00000000000 --- a/spec/factories/form4142_status_polling_records.rb +++ /dev/null @@ -1,26 +0,0 @@ -# frozen_string_literal: true - -FactoryBot.define do - factory :form4142_status_polling_record do - benefits_intake_uuid { 'MyString' } - submission_id { 1 } - submission_class { 'Form526Submission' } - status { 0 } - - trait :pending do - status { 0 } - end - - trait :has_vcr_data do - benefits_intake_uuid { '6d8433c1-cd55-4c24-affd-f592287a7572' } - end - - trait :errored do - status { 1 } - end - - trait :success do - status { 2 } - end - end -end diff --git a/spec/models/form4142_status_polling_record_spec.rb b/spec/models/form4142_status_polling_record_spec.rb deleted file mode 100644 index 934e16942c0..00000000000 --- a/spec/models/form4142_status_polling_record_spec.rb +++ /dev/null @@ -1,37 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -RSpec.describe Form4142StatusPollingRecord, type: :model do - describe 'successful creation' do - it 'when all attrs provided' do - polling_record = Form4142StatusPollingRecord.new(benefits_intake_uuid: '123', submission_id: 123, - submission_class: 'Class') - polling_record.save! - expect(polling_record.status).to eq('pending') - end - end - - describe 'errors' do - it 'when missing submission_id' do - expect do - polling_record = Form4142StatusPollingRecord.new(benefits_intake_uuid: '123') - polling_record.save! - end.to raise_error(ActiveRecord::RecordInvalid) - end - - it 'when missing benefits_intake_uuid' do - expect do - polling_record = Form4142StatusPollingRecord.new(submission_id: 123) - polling_record.save! - end.to raise_error(ActiveRecord::RecordInvalid) - end - - it 'when missing both benefits_intake_uuid and submission_id' do - expect do - polling_record = Form4142StatusPollingRecord.new - polling_record.save! - end.to raise_error(ActiveRecord::RecordInvalid) - end - end -end From 5955c9ba40d1b57ba3973f519a9d00a99d8c7ed1 Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Wed, 16 Oct 2024 13:06:15 -0400 Subject: [PATCH 17/58] altering tests --- app/sidekiq/central_mail/submit_form4142_job.rb | 12 +++++------- .../central_mail/submit_form4142_job_spec.rb | 14 ++++++++------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/sidekiq/central_mail/submit_form4142_job.rb b/app/sidekiq/central_mail/submit_form4142_job.rb index 609f90d19da..7c3de848c19 100644 --- a/app/sidekiq/central_mail/submit_form4142_job.rb +++ b/app/sidekiq/central_mail/submit_form4142_job.rb @@ -152,23 +152,21 @@ def upload_to_lighthouse payload = payload_hash(lighthouse_service.location) lighthouse_service.upload_doc(**payload) + log_info = { benefits_intake_uuid: lighthouse_service.uuid, submission_id: @submission_id} + if Flipper.enabled?(POLLING_FLIPPER_KEY) form526_submission = Form526Submission.find(@submission_id) form_submission = FormSubmission.create( form_type: FORM4142_FORMSUBMISSION_TYPE, # form526_form4142 benefits_intake_uuid: lighthouse_service.uuid, - form_data: {}, # maybe? + form_data: '{}', # we have this already in the Form526Submission.form['form526']['form526']['form4142'], dont know we need to duplicate here? user_account: form526_submission.user_account, saved_claim: form526_submission.saved_claim ) FormSubmissionAttempt.create(form_submission:) + log_info[:form_submission_id] = form_submission.id end - - Rails.logger.info( - 'Successful Form4142 Submission to Lighthouse', - { benefits_intake_uuid: lighthouse_service.uuid, submission_id: @submission_id, - polling_record_id: polling_record.id } - ) + Rails.logger.info('Successful Form4142 Submission to Lighthouse', log_info) end def generate_metadata diff --git a/spec/sidekiq/central_mail/submit_form4142_job_spec.rb b/spec/sidekiq/central_mail/submit_form4142_job_spec.rb index cb8f8b20455..63fe1eaab09 100644 --- a/spec/sidekiq/central_mail/submit_form4142_job_spec.rb +++ b/spec/sidekiq/central_mail/submit_form4142_job_spec.rb @@ -204,7 +204,8 @@ end.to change(subject.jobs, :size).by(1) end - it 'Creates a form 4142 submission polling record' do + it 'Creates a form 4142 submission polling record, when enabled' do + Flipper.enable(CentralMail::SubmitForm4142Job::POLLING_FLIPPER_KEY) expect do VCR.use_cassette('lighthouse/benefits_intake/200_lighthouse_intake_upload_location') do VCR.use_cassette('lighthouse/benefits_intake/200_lighthouse_intake_upload') do @@ -212,11 +213,12 @@ described_class.drain end end - end.to change(Form4142StatusPollingRecord, :count).by(1) - record = Form4142StatusPollingRecord.last - expect(record.submission_id).to eq(submission.id) - expect(record.status).to eq('pending') - expect(record.submission_class).to eq('Form526Submission') + end.to change(FormSubmission, :count).by(1) + .and change(FormSubmissionAttempt, :count).by(1) + fs_record = FormSubmission.last + fs_attempt_record = FormSubmissionAttempt.last + expect(Form526Submission.find_by(saved_claim_id: fs_record.saved_claim_id).id).to eq(submission.id) + expect(fs_attempt_record.state).to eq('pending') end it 'submits successfully' do From 397b1e80a2f7e899c5cc2e4f1fc1ad3cd867a11f Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Wed, 16 Oct 2024 14:48:06 -0400 Subject: [PATCH 18/58] Rubocop --- app/models/form_submission_attempt.rb | 18 +++++------ .../central_mail/submit_form4142_job.rb | 4 +-- spec/models/form_submission_attempt_spec.rb | 32 ++++++++++++++++++- .../central_mail/submit_form4142_job_spec.rb | 17 ++++++++-- 4 files changed, 57 insertions(+), 14 deletions(-) diff --git a/app/models/form_submission_attempt.rb b/app/models/form_submission_attempt.rb index 32c53295e7d..9d751275842 100644 --- a/app/models/form_submission_attempt.rb +++ b/app/models/form_submission_attempt.rb @@ -25,17 +25,17 @@ class FormSubmissionAttempt < ApplicationRecord event :fail do after do - Rails.logger.info({ - message: 'Preparing to send Form Submission Attempt error email', - form_submission_id:, - benefits_intake_uuid: form_submission&.benefits_intake_uuid, - form_type: form_submission&.form_type - }) - is_form526_form4142 = form_type == CentralMail::SubmitForm4142Job::FORM4142_FORMSUBMISSION_TYPE + log_info = { form_submission_id:, + benefits_intake_uuid: form_submission&.benefits_intake_uuid, + form_type: form_submission&.form_type } + Rails.logger.info('Preparing to send Form Submission Attempt error email', log_info) + is_form526_form4142 = form_submission.form_type == CentralMail::SubmitForm4142Job::FORM4142_FORMSUBMISSION_TYPE if Flipper.enabled?(:simple_forms_email_notifications) && !is_form526_form4142 - enqueue_result_email(:error) + enqueue_result_email(:error) elsif Flipper.enabled?(:form526_send_4142_failure_notification) && is_form526_form4142 - EVSS::DisabilityCompensationForm::Form4142DocumentUploadFailureEmail.perform_async(Form526Submission.find_by(saved_claim_id:).id) + Rails.logger.info('Sending Form526:Form4142 failure email', log_info) + jid = EVSS::DisabilityCompensationForm::Form4142DocumentUploadFailureEmail.perform_async(Form526Submission.find_by(saved_claim_id:).id) + Rails.logger.info('Sent Form526:Form4142 failure email', log_info.merge({ jid: })) end end diff --git a/app/sidekiq/central_mail/submit_form4142_job.rb b/app/sidekiq/central_mail/submit_form4142_job.rb index 7c3de848c19..523ba1b664c 100644 --- a/app/sidekiq/central_mail/submit_form4142_job.rb +++ b/app/sidekiq/central_mail/submit_form4142_job.rb @@ -11,7 +11,7 @@ module CentralMail class SubmitForm4142Job < EVSS::DisabilityCompensationForm::Job POLLING_FLIPPER_KEY = :disability_526_form4142_polling_records - FORM4142_FORMSUBMISSION_TYPE = "#{Form526Submission::FORM_526}_#{Form526Submission::FORM_4142}" + FORM4142_FORMSUBMISSION_TYPE = "#{Form526Submission::FORM_526}_#{Form526Submission::FORM_4142}".freeze extend Logging::ThirdPartyTransaction::MethodWrapper # this is required to make instance variables available to logs via @@ -152,7 +152,7 @@ def upload_to_lighthouse payload = payload_hash(lighthouse_service.location) lighthouse_service.upload_doc(**payload) - log_info = { benefits_intake_uuid: lighthouse_service.uuid, submission_id: @submission_id} + log_info = { benefits_intake_uuid: lighthouse_service.uuid, submission_id: @submission_id } if Flipper.enabled?(POLLING_FLIPPER_KEY) form526_submission = Form526Submission.find(@submission_id) diff --git a/spec/models/form_submission_attempt_spec.rb b/spec/models/form_submission_attempt_spec.rb index 8c38acd0b4f..0d11e343e0a 100644 --- a/spec/models/form_submission_attempt_spec.rb +++ b/spec/models/form_submission_attempt_spec.rb @@ -20,6 +20,12 @@ context 'transitioning to a failure state' do let(:notification_type) { :error } + let(:vanotify_client) { instance_double(VaNotify::Service) } + let!(:form526_submission) { create(:form526_submission) } + let!(:form526_form4142_form_submission) do + create(:form_submission, saved_claim_id: form526_submission.saved_claim.id, + form_type: CentralMail::SubmitForm4142Job::FORM4142_FORMSUBMISSION_TYPE) + end it 'transitions to a failure state' do form_submission_attempt = create(:form_submission_attempt) @@ -28,7 +34,7 @@ .to transition_from(:pending).to(:failure).on_event(:fail) end - it 'sends an error email' do + it 'sends an error email when it is a SimpleFormsApi supported form' do notification_email = double allow(notification_email).to receive(:send) allow(SimpleFormsApi::NotificationEmail).to receive(:new).with( @@ -42,6 +48,30 @@ expect(notification_email).to have_received(:send) end + + it 'sends an error email when it is not a SimpleFormsApi form and flippers are on' do + Flipper.enable(:form526_send_4142_failure_notification) + Flipper.enable(CentralMail::SubmitForm4142Job::POLLING_FLIPPER_KEY) + + email_klass = EVSS::DisabilityCompensationForm::Form4142DocumentUploadFailureEmail + form_submission_attempt = FormSubmissionAttempt.create(form_submission: form526_form4142_form_submission) + + mocked_notification_service = instance_double(VaNotify::Service) + allow(VaNotify::Service).to receive(:new).and_return(mocked_notification_service) + allow(mocked_notification_service).to receive(:send_email).and_return(true) + + with_settings(Settings.vanotify.services.benefits_disability, { api_key: 'test_service_api_key' }) do + expect do + form_submission_attempt.fail! + email_klass.drain + end.to trigger_statsd_increment("#{email_klass::STATSD_METRIC_PREFIX}.success") + .and change(Form526JobStatus, :count).by(1) + + job_tracking = Form526JobStatus.last + expect(job_tracking.form526_submission_id).to eq(form526_submission.id) + expect(job_tracking.job_class).to eq(email_klass.class_name) + end + end end it 'transitions to a success state' do diff --git a/spec/sidekiq/central_mail/submit_form4142_job_spec.rb b/spec/sidekiq/central_mail/submit_form4142_job_spec.rb index 63fe1eaab09..de2b9b69b39 100644 --- a/spec/sidekiq/central_mail/submit_form4142_job_spec.rb +++ b/spec/sidekiq/central_mail/submit_form4142_job_spec.rb @@ -214,13 +214,26 @@ end end end.to change(FormSubmission, :count).by(1) - .and change(FormSubmissionAttempt, :count).by(1) - fs_record = FormSubmission.last + .and change(FormSubmissionAttempt, :count).by(1) + fs_record = FormSubmission.last fs_attempt_record = FormSubmissionAttempt.last expect(Form526Submission.find_by(saved_claim_id: fs_record.saved_claim_id).id).to eq(submission.id) expect(fs_attempt_record.state).to eq('pending') end + it 'Does not creates a form 4142 submission polling record, when disabled' do + Flipper.disable(CentralMail::SubmitForm4142Job::POLLING_FLIPPER_KEY) + expect do + VCR.use_cassette('lighthouse/benefits_intake/200_lighthouse_intake_upload_location') do + VCR.use_cassette('lighthouse/benefits_intake/200_lighthouse_intake_upload') do + subject.perform_async(submission.id) + described_class.drain + end + end + end.to change(FormSubmission, :count).by(0) + .and change(FormSubmissionAttempt, :count).by(0) + end + it 'submits successfully' do VCR.use_cassette('lighthouse/benefits_intake/200_lighthouse_intake_upload_location') do VCR.use_cassette('lighthouse/benefits_intake/200_lighthouse_intake_upload') do From 577fbe711f8c7bca5adf70c65de53d08e1540ddd Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Wed, 16 Oct 2024 15:05:17 -0400 Subject: [PATCH 19/58] Rubocopin --- app/models/form_submission_attempt.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/form_submission_attempt.rb b/app/models/form_submission_attempt.rb index 9d751275842..8c2d410c11f 100644 --- a/app/models/form_submission_attempt.rb +++ b/app/models/form_submission_attempt.rb @@ -33,8 +33,9 @@ class FormSubmissionAttempt < ApplicationRecord if Flipper.enabled?(:simple_forms_email_notifications) && !is_form526_form4142 enqueue_result_email(:error) elsif Flipper.enabled?(:form526_send_4142_failure_notification) && is_form526_form4142 - Rails.logger.info('Sending Form526:Form4142 failure email', log_info) - jid = EVSS::DisabilityCompensationForm::Form4142DocumentUploadFailureEmail.perform_async(Form526Submission.find_by(saved_claim_id:).id) + form526_submission_id = Form526Submission.find_by(saved_claim_id:).id + Rails.logger.info('Sending Form526:Form4142 failure email', log_info.merge({ form526_submission_id: })) + jid = EVSS::DisabilityCompensationForm::Form4142DocumentUploadFailureEmail.perform_async(form526_submission_id) Rails.logger.info('Sent Form526:Form4142 failure email', log_info.merge({ jid: })) end end From bdc11953fa0b192244e18683e170f7a525db0d65 Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Thu, 17 Oct 2024 07:48:00 -0400 Subject: [PATCH 20/58] Changing to pass --- spec/sidekiq/central_mail/submit_form4142_job_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/sidekiq/central_mail/submit_form4142_job_spec.rb b/spec/sidekiq/central_mail/submit_form4142_job_spec.rb index de2b9b69b39..aecb90f170f 100644 --- a/spec/sidekiq/central_mail/submit_form4142_job_spec.rb +++ b/spec/sidekiq/central_mail/submit_form4142_job_spec.rb @@ -218,7 +218,7 @@ fs_record = FormSubmission.last fs_attempt_record = FormSubmissionAttempt.last expect(Form526Submission.find_by(saved_claim_id: fs_record.saved_claim_id).id).to eq(submission.id) - expect(fs_attempt_record.state).to eq('pending') + expect(fs_attempt_record.pending?).to be(true) end it 'Does not creates a form 4142 submission polling record, when disabled' do From 45e0d629d9deddb2c037bb1abeb77b921073a41d Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Thu, 17 Oct 2024 07:49:14 -0400 Subject: [PATCH 21/58] Undoing db changes no longer needed --- db/schema.rb | 74 ++++++++++++---------------------------------------- 1 file changed, 17 insertions(+), 57 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index 6862f14ddf0..a1a9c335a6c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_10_08_150707) do +ActiveRecord::Schema[7.1].define(version: 2024_10_14_205528) do # These are extensions that must be enabled in order to support this database enable_extension "btree_gin" enable_extension "fuzzystrmatch" @@ -165,6 +165,7 @@ t.string "lighthouse_upload_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.datetime "failure_notification_sent_at" end create_table "appeal_submissions", force: :cascade do |t| @@ -177,6 +178,7 @@ t.text "upload_metadata_ciphertext" t.text "encrypted_kms_key" t.uuid "user_account_id" + t.datetime "failure_notification_sent_at" t.index ["user_account_id"], name: "index_appeal_submissions_on_user_account_id" end @@ -466,18 +468,6 @@ t.index ["sid"], name: "index_covid_vaccine_registry_submissions_on_sid", unique: true end - create_table "credential_adoption_email_records", force: :cascade do |t| - t.string "icn", null: false - t.string "email_address", null: false - t.string "email_template_id", null: false - t.datetime "email_triggered_at", precision: nil - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["email_address"], name: "index_credential_adoption_email_records_on_email_address" - t.index ["email_template_id"], name: "index_credential_adoption_email_records_on_email_template_id" - t.index ["icn"], name: "index_credential_adoption_email_records_on_icn" - end - create_table "deprecated_user_accounts", force: :cascade do |t| t.uuid "user_account_id" t.bigint "user_verification_id" @@ -588,16 +578,6 @@ t.index ["user_uuid"], name: "index_education_stem_automated_decisions_on_user_uuid" end - create_table "email_records", force: :cascade do |t| - t.string "va_notify_id" - t.integer "email_type" - t.integer "email_state" - t.integer "tracked_item_id" - t.string "tracked_item_class" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - end - create_table "evss_claims", id: :serial, force: :cascade do |t| t.integer "evss_id", null: false t.json "data", null: false @@ -674,15 +654,6 @@ t.index ["veteran_icn", "tax_year"], name: "index_form1095_bs_on_veteran_icn_and_tax_year", unique: true end - create_table "form4142_status_polling_records", force: :cascade do |t| - t.string "benefits_intake_uuid" - t.integer "submission_id" - t.string "submission_class" - t.integer "status" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - end - create_table "form526_job_statuses", id: :serial, force: :cascade do |t| t.integer "form526_submission_id", null: false t.string "job_id", null: false @@ -704,6 +675,7 @@ t.boolean "ignored_as_duplicate", default: false t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.integer "remediation_type", default: 0 t.index ["form526_submission_id"], name: "index_form526_submission_remediations_on_form526_submission_id" end @@ -865,13 +837,6 @@ t.index ["user_uuid"], name: "index_in_progress_forms_on_user_uuid" end - create_table "inherited_proof_verified_user_accounts", force: :cascade do |t| - t.uuid "user_account_id", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["user_account_id"], name: "index_inherited_proof_verified_user_accounts_on_user_account_id", unique: true - end - create_table "intent_to_file_queue_exhaustions", force: :cascade do |t| t.string "veteran_icn", null: false t.string "form_type" @@ -1343,15 +1308,21 @@ t.index ["user_account_id", "form_id"], name: "index_in_progress_reminders_sent_user_account_form_id", unique: true end - create_table "vba_documents_git_items", force: :cascade do |t| - t.string "url", null: false - t.jsonb "git_item" - t.boolean "notified", default: false - t.string "label" + create_table "va_notify_notifications", force: :cascade do |t| + t.uuid "notification_id", null: false + t.text "reference" + t.text "to" + t.text "status" + t.datetime "completed_at" + t.datetime "sent_at" + t.text "notification_type" + t.text "status_reason" + t.text "provider" + t.text "source_location" + t.text "callback" t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.index ["notified", "label"], name: "index_vba_documents_git_items_on_notified_and_label" - t.index ["url"], name: "index_vba_documents_git_items_on_url", unique: true + t.string "metadata" end create_table "vba_documents_monthly_stats", force: :cascade do |t| @@ -1383,17 +1354,6 @@ t.index ["status"], name: "index_vba_documents_upload_submissions_on_status" end - create_table "versions", force: :cascade do |t| - t.string "item_type", null: false - t.bigint "item_id", null: false - t.string "event", null: false - t.string "whodunnit" - t.text "object" - t.datetime "created_at", precision: nil - t.text "object_changes" - t.index ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id" - end - create_table "veteran_device_records", force: :cascade do |t| t.bigint "device_id", null: false t.boolean "active", default: true, null: false From 8289238727130df9b6be629b550bc0ef856b9085 Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Thu, 17 Oct 2024 07:56:17 -0400 Subject: [PATCH 22/58] unresolved merge fixes --- db/schema.rb | 6 ------ 1 file changed, 6 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index 174ee5e8751..bb3cba05f16 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -166,10 +166,7 @@ t.datetime "created_at", null: false t.datetime "updated_at", null: false t.datetime "failure_notification_sent_at" -<<<<<<< HEAD -======= t.index ["appeal_submission_id"], name: "index_appeal_submission_uploads_on_appeal_submission_id" ->>>>>>> master end create_table "appeal_submissions", force: :cascade do |t| @@ -183,10 +180,7 @@ t.text "encrypted_kms_key" t.uuid "user_account_id" t.datetime "failure_notification_sent_at" -<<<<<<< HEAD -======= t.index ["submitted_appeal_uuid"], name: "index_appeal_submissions_on_submitted_appeal_uuid" ->>>>>>> master t.index ["user_account_id"], name: "index_appeal_submissions_on_user_account_id" end From 86a35ee8a5aee7248253e557a4ecdf0392ff5a6d Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Thu, 17 Oct 2024 08:06:43 -0400 Subject: [PATCH 23/58] Removing benefits intake service class to another PR --- .../benefits_intake_status_polling_job.rb | 42 ------------------- .../form526_paranoid_success_polling_job.rb | 23 +++++++++- app/sidekiq/form526_status_polling_job.rb | 22 ++++++++-- 3 files changed, 40 insertions(+), 47 deletions(-) delete mode 100644 app/sidekiq/benefits_intake_status_polling_job.rb diff --git a/app/sidekiq/benefits_intake_status_polling_job.rb b/app/sidekiq/benefits_intake_status_polling_job.rb deleted file mode 100644 index 1a85ec08167..00000000000 --- a/app/sidekiq/benefits_intake_status_polling_job.rb +++ /dev/null @@ -1,42 +0,0 @@ -# frozen_string_literal: true - -require 'benefits_intake_service/service' - -class BenefitsIntakeStatusPollingJob - include Sidekiq::Job - sidekiq_options retry: false - - STATS_KEY = 'api.benefits_intake.polled_status' - MAX_BATCH_SIZE = 1000 - attr_reader :max_batch_size - - def initialize(max_batch_size: MAX_BATCH_SIZE) - @max_batch_size = max_batch_size - @total_handled = 0 - end - - def perform - Rails.logger.info('Beginning Form 526 Intake Status polling') - submissions.in_batches(of: max_batch_size) do |batch| - batch_ids = batch.pluck(:backup_submitted_claim_id).flatten - response = api_to_poll.get_bulk_status_of_uploads(batch_ids) - handle_response(response) - end - Rails.logger.info('Form 526 Intake Status polling complete', - total_handled: @total_handled) - rescue => e - Rails.logger.error('Error processing 526 Intake Status batch', - class: self.class.name, message: e.message) - end - - private - - def api_to_poll - @api_to_poll ||= BenefitsIntakeService::Service.new - end - - def submissions - raise NotImplementedError, - "Required submissions records method not implimented. Impliment a `#{self.class.name}.submissions` method." - end -end diff --git a/app/sidekiq/form526_paranoid_success_polling_job.rb b/app/sidekiq/form526_paranoid_success_polling_job.rb index 4c72533b081..1f7eba24f1e 100644 --- a/app/sidekiq/form526_paranoid_success_polling_job.rb +++ b/app/sidekiq/form526_paranoid_success_polling_job.rb @@ -2,7 +2,7 @@ require 'benefits_intake_service/service' -class Form526ParanoidSuccessPollingJob < BenefitsIntakeStatusPollingJob +class Form526ParanoidSuccessPollingJob include Sidekiq::Job sidekiq_options retry: false @@ -10,12 +10,31 @@ class Form526ParanoidSuccessPollingJob < BenefitsIntakeStatusPollingJob attr_reader :max_batch_size, :change_totals, :total_checked def initialize(max_batch_size: MAX_BATCH_SIZE) - super + @max_batch_size = max_batch_size + @total_checked = 0 @change_totals = {} end + def perform + Rails.logger.info('Beginning Form 526 paranoid_success polling') + submissions.in_batches(of: max_batch_size) do |batch| + batch_ids = batch.pluck(:backup_submitted_claim_id).flatten + response = api_to_poll.get_bulk_status_of_uploads(batch_ids) + handle_response(response) + end + Rails.logger.info('Form 526 paranoid_success polling complete', + total_checked:, change_totals:) + rescue => e + Rails.logger.error('Error processing 526 paranoid_success batch', + class: self.class.name, message: e.message) + end + private + def api_to_poll + @api_to_poll ||= BenefitsIntakeService::Service.new + end + def submissions @submissions ||= Form526Submission.paranoid_success_type end diff --git a/app/sidekiq/form526_status_polling_job.rb b/app/sidekiq/form526_status_polling_job.rb index 14db34de401..b57dbf7dc5d 100644 --- a/app/sidekiq/form526_status_polling_job.rb +++ b/app/sidekiq/form526_status_polling_job.rb @@ -2,7 +2,19 @@ require 'benefits_intake_service/service' -class Form526StatusPollingJob < BenefitsIntakeStatusPollingJob +class Form526StatusPollingJob + include Sidekiq::Job + sidekiq_options retry: false + + STATS_KEY = 'api.benefits_intake.submission_status' + MAX_BATCH_SIZE = 1000 + attr_reader :max_batch_size + + def initialize(max_batch_size: MAX_BATCH_SIZE) + @max_batch_size = max_batch_size + @total_handled = 0 + end + def perform Rails.logger.info('Beginning Form 526 Intake Status polling') submissions.in_batches(of: max_batch_size) do |batch| @@ -19,6 +31,10 @@ def perform private + def api_to_poll + @api_to_poll ||= BenefitsIntakeService::Service.new + end + def submissions @submissions ||= Form526Submission.pending_backup end @@ -53,7 +69,7 @@ def handle_submission(status, form_submission) end def log_result(result) - StatsD.increment("#{STATS_KEY}.submission_status.526.#{result}") - StatsD.increment("#{STATS_KEY}.submission_status.all_forms.#{result}") + StatsD.increment("#{STATS_KEY}.526.#{result}") + StatsD.increment("#{STATS_KEY}.all_forms.#{result}") end end From 8d9533213f1d5b9459f18bc57d10110f50d3bb76 Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Thu, 17 Oct 2024 13:01:21 -0400 Subject: [PATCH 24/58] rubocoping --- app/models/form_profile.rb | 4 ++-- app/models/form_submission_attempt.rb | 20 ++++++++++++------- .../central_mail/submit_form4142_job.rb | 3 +-- .../central_mail/submit_form4142_job_spec.rb | 4 ++-- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/app/models/form_profile.rb b/app/models/form_profile.rb index 238861660ff..3c543834a92 100644 --- a/app/models/form_profile.rb +++ b/app/models/form_profile.rb @@ -358,10 +358,10 @@ def pciu_us_phone # preference: vet360 mobile -> vet360 home -> pciu def phone_object mobile = vet360_contact_info&.mobile_phone - return mobile if mobile&.area_code && mobile.phone_number + return mobile if mobile&.area_code && mobile&.phone_number home = vet360_contact_info&.home_phone - return home if home&.area_code && home.phone_number + return home if home&.area_code && home&.phone_number phone_struct = Struct.new(:area_code, :phone_number) diff --git a/app/models/form_submission_attempt.rb b/app/models/form_submission_attempt.rb index ab6c244ed34..64591eff86d 100644 --- a/app/models/form_submission_attempt.rb +++ b/app/models/form_submission_attempt.rb @@ -29,14 +29,18 @@ class FormSubmissionAttempt < ApplicationRecord benefits_intake_uuid: form_submission&.benefits_intake_uuid, form_type: form_submission&.form_type } if should_send_simple_forms_email - Rails.logger.info('Preparing to send Form Submission Attempt error email', log_info) + Rails.logger.info('Preparing to send Form Submission Attempt error email', log_info) simple_forms_enqueue_result_email(:error) - else should_send_form526_form4142_email + else + # Do not love hard coding this in here like this. + # Hoping to refactor this at somepoint to better support various emailing on arbitrary or inherited classes + should_send_form526_form4142_email form526_submission_id = Form526Submission.find_by(saved_claim_id:).id - Rails.logger.info('Sending Form526:Form4142 failure email', log_info.merge({ form526_submission_id: })) - jid = EVSS::DisabilityCompensationForm::Form4142DocumentUploadFailureEmail.perform_async(form526_submission_id) - Rails.logger.info('Sent Form526:Form4142 failure email', log_info.merge({ jid: })) - end + Rails.logger.info('Queuing Form526:Form4142 failure email to VaNotify', + log_info.merge({ form526_submission_id: })) + jid = EVSS::DisabilityCompensationForm::Form4142DocumentUploadFailureEmail.perform_async form526_submission_id + Rails.logger.info('Queuing Form526:Form4142 failure email to VaNotify completed', log_info.merge({ jid: })) + end end transitions from: :pending, to: :failure @@ -89,7 +93,9 @@ def should_send_simple_forms_email def should_send_form526_form4142_email email_klass = CentralMail::SubmitForm4142Job - form_submission.form_type == email_klass::FORM4142_FORMSUBMISSION_TYPE && Flipper.enabled?(email_klass::POLLED_FAILURE_EMAIL) + email_klass_form_type = email_klass::FORM4142_FORMSUBMISSION_TYPE + email_klass_polled_failure_email_enabled = Flipper.enabled?(email_klass::POLLED_FAILURE_EMAIL) + form_submission.form_type == email_klass_form_type && email_klass_polled_failure_email_enabled end def simple_forms_enqueue_result_email(notification_type) diff --git a/app/sidekiq/central_mail/submit_form4142_job.rb b/app/sidekiq/central_mail/submit_form4142_job.rb index 53d8be36c6d..666cceec639 100644 --- a/app/sidekiq/central_mail/submit_form4142_job.rb +++ b/app/sidekiq/central_mail/submit_form4142_job.rb @@ -13,7 +13,6 @@ class SubmitForm4142Job < EVSS::DisabilityCompensationForm::Job POLLING_FLIPPER_KEY = :disability_526_form4142_polling_records POLLED_FAILURE_EMAIL = :disability_526_form4142_polling_record_failure_email - FORM4142_FORMSUBMISSION_TYPE = "#{Form526Submission::FORM_526}_#{Form526Submission::FORM_4142}".freeze extend Logging::ThirdPartyTransaction::MethodWrapper @@ -162,7 +161,7 @@ def upload_to_lighthouse form_submission = FormSubmission.create( form_type: FORM4142_FORMSUBMISSION_TYPE, # form526_form4142 benefits_intake_uuid: lighthouse_service.uuid, - form_data: '{}', # we have this already in the Form526Submission.form['form526']['form526']['form4142'], dont know we need to duplicate here? + form_data: '{}', # we have this already in the Form526Submission.form['form526']['form526']['form4142'] user_account: form526_submission.user_account, saved_claim: form526_submission.saved_claim ) diff --git a/spec/sidekiq/central_mail/submit_form4142_job_spec.rb b/spec/sidekiq/central_mail/submit_form4142_job_spec.rb index aecb90f170f..dc0852b1160 100644 --- a/spec/sidekiq/central_mail/submit_form4142_job_spec.rb +++ b/spec/sidekiq/central_mail/submit_form4142_job_spec.rb @@ -230,8 +230,8 @@ described_class.drain end end - end.to change(FormSubmission, :count).by(0) - .and change(FormSubmissionAttempt, :count).by(0) + end.not.to change(FormSubmission, :count) + .and.not_to change(FormSubmissionAttempt, :count) end it 'submits successfully' do From 1b4e5d5e89e0bfdcbf8d78e93c7f2d5d0bb55951 Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Thu, 17 Oct 2024 13:07:39 -0400 Subject: [PATCH 25/58] Not sure where this came from but undoing it --- app/models/form_profile.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/form_profile.rb b/app/models/form_profile.rb index 3c543834a92..238861660ff 100644 --- a/app/models/form_profile.rb +++ b/app/models/form_profile.rb @@ -358,10 +358,10 @@ def pciu_us_phone # preference: vet360 mobile -> vet360 home -> pciu def phone_object mobile = vet360_contact_info&.mobile_phone - return mobile if mobile&.area_code && mobile&.phone_number + return mobile if mobile&.area_code && mobile.phone_number home = vet360_contact_info&.home_phone - return home if home&.area_code && home&.phone_number + return home if home&.area_code && home.phone_number phone_struct = Struct.new(:area_code, :phone_number) From df3fb23a9c306a617e6ab878cdf28c68d6ae7943 Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Thu, 17 Oct 2024 13:59:16 -0400 Subject: [PATCH 26/58] Fixing location of bool --- app/models/form_submission_attempt.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/models/form_submission_attempt.rb b/app/models/form_submission_attempt.rb index 64591eff86d..38fbd63af38 100644 --- a/app/models/form_submission_attempt.rb +++ b/app/models/form_submission_attempt.rb @@ -31,10 +31,9 @@ class FormSubmissionAttempt < ApplicationRecord if should_send_simple_forms_email Rails.logger.info('Preparing to send Form Submission Attempt error email', log_info) simple_forms_enqueue_result_email(:error) - else + elsif should_send_form526_form4142_email # Do not love hard coding this in here like this. - # Hoping to refactor this at somepoint to better support various emailing on arbitrary or inherited classes - should_send_form526_form4142_email + # Hoping to refactor this at somepoint to better support various emailing on arbitrary or inherited classes form526_submission_id = Form526Submission.find_by(saved_claim_id:).id Rails.logger.info('Queuing Form526:Form4142 failure email to VaNotify', log_info.merge({ form526_submission_id: })) From 19888ee800563873b2fcb4310bd2c069e0cdcd6c Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Fri, 18 Oct 2024 16:02:11 -0400 Subject: [PATCH 27/58] Rubocop --- app/models/form_submission_attempt.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/form_submission_attempt.rb b/app/models/form_submission_attempt.rb index 38fbd63af38..ede73855cf4 100644 --- a/app/models/form_submission_attempt.rb +++ b/app/models/form_submission_attempt.rb @@ -33,7 +33,7 @@ class FormSubmissionAttempt < ApplicationRecord simple_forms_enqueue_result_email(:error) elsif should_send_form526_form4142_email # Do not love hard coding this in here like this. - # Hoping to refactor this at somepoint to better support various emailing on arbitrary or inherited classes + # Hoping to refactor this at somepoint to better support various emailing on arbitrary or inherited classes form526_submission_id = Form526Submission.find_by(saved_claim_id:).id Rails.logger.info('Queuing Form526:Form4142 failure email to VaNotify', log_info.merge({ form526_submission_id: })) From b56dc0151a432fa722dab1d73c09df28c76488e1 Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Mon, 21 Oct 2024 08:15:08 -0400 Subject: [PATCH 28/58] Adding test case for flippers off --- spec/models/form_submission_attempt_spec.rb | 71 +++++++++++++-------- 1 file changed, 44 insertions(+), 27 deletions(-) diff --git a/spec/models/form_submission_attempt_spec.rb b/spec/models/form_submission_attempt_spec.rb index ea17298c08b..61a9756c2c1 100644 --- a/spec/models/form_submission_attempt_spec.rb +++ b/spec/models/form_submission_attempt_spec.rb @@ -23,11 +23,6 @@ context 'transitioning to a failure state' do let(:notification_type) { :error } let(:vanotify_client) { instance_double(VaNotify::Service) } - let!(:form526_submission) { create(:form526_submission) } - let!(:form526_form4142_form_submission) do - create(:form_submission, saved_claim_id: form526_submission.saved_claim.id, - form_type: CentralMail::SubmitForm4142Job::FORM4142_FORMSUBMISSION_TYPE) - end it 'transitions to a failure state' do form_submission_attempt = create(:form_submission_attempt) @@ -66,29 +61,51 @@ expect(SimpleFormsApi::NotificationEmail).not_to have_received(:new) end - end - - it 'sends an 4142 error email when it is not a SimpleFormsApi form and flippers are on' do - Flipper.enable(CentralMail::SubmitForm4142Job::POLLING_FLIPPER_KEY) - Flipper.enable(CentralMail::SubmitForm4142Job::POLLED_FAILURE_EMAIL) - - email_klass = EVSS::DisabilityCompensationForm::Form4142DocumentUploadFailureEmail - form_submission_attempt = FormSubmissionAttempt.create(form_submission: form526_form4142_form_submission) - - mocked_notification_service = instance_double(VaNotify::Service) - allow(VaNotify::Service).to receive(:new).and_return(mocked_notification_service) - allow(mocked_notification_service).to receive(:send_email).and_return(true) - - with_settings(Settings.vanotify.services.benefits_disability, { api_key: 'test_service_api_key' }) do - expect do - form_submission_attempt.fail! - email_klass.drain - end.to trigger_statsd_increment("#{email_klass::STATSD_METRIC_PREFIX}.success") - .and change(Form526JobStatus, :count).by(1) - job_tracking = Form526JobStatus.last - expect(job_tracking.form526_submission_id).to eq(form526_submission.id) - expect(job_tracking.job_class).to eq(email_klass.class_name) + context 'is a form526_form4142 form' do + let!(:email_klass) { EVSS::DisabilityCompensationForm::Form4142DocumentUploadFailureEmail } + let(:mocked_notification_service) { instance_double(VaNotify::Service) } + let!(:form526_submission) { create(:form526_submission) } + let!(:form526_form4142_form_submission) do + create(:form_submission, saved_claim_id: form526_submission.saved_claim.id, + form_type: CentralMail::SubmitForm4142Job::FORM4142_FORMSUBMISSION_TYPE) + end + let!(:form_submission_attempt) do + FormSubmissionAttempt.create(form_submission: form526_form4142_form_submission) + end + + it 'sends an 4142 error email when it is not a SimpleFormsApi form and flippers are on' do + Flipper.enable(CentralMail::SubmitForm4142Job::POLLING_FLIPPER_KEY) + Flipper.enable(CentralMail::SubmitForm4142Job::POLLED_FAILURE_EMAIL) + + allow(VaNotify::Service).to receive(:new).and_return(mocked_notification_service) + allow(mocked_notification_service).to receive(:send_email).and_return(true) + + with_settings(Settings.vanotify.services.benefits_disability, { api_key: 'test_service_api_key' }) do + expect do + form_submission_attempt.fail! + email_klass.drain + end.to trigger_statsd_increment("#{email_klass::STATSD_METRIC_PREFIX}.success") + .and change(Form526JobStatus, :count).by(1) + + job_tracking = Form526JobStatus.last + expect(job_tracking.form526_submission_id).to eq(form526_submission.id) + expect(job_tracking.job_class).to eq(email_klass.class_name) + end + end + + it 'does not send an 4142 error email when it is not a SimpleFormsApi form and flippers are off' do + Flipper.disable(CentralMail::SubmitForm4142Job::POLLING_FLIPPER_KEY) + Flipper.disable(CentralMail::SubmitForm4142Job::POLLED_FAILURE_EMAIL) + + with_settings(Settings.vanotify.services.benefits_disability, { api_key: 'test_service_api_key' }) do + expect do + form_submission_attempt.fail! + email_klass.drain + end.to not_trigger_statsd_increment("#{email_klass::STATSD_METRIC_PREFIX}.success") + .and not_change(Form526JobStatus, :count) + end + end end end end From 23c52a7d1a0ff1cb9536d89868842be6bce22d59 Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Mon, 21 Oct 2024 08:17:16 -0400 Subject: [PATCH 29/58] Removing dup let --- spec/models/form_submission_attempt_spec.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/spec/models/form_submission_attempt_spec.rb b/spec/models/form_submission_attempt_spec.rb index 61a9756c2c1..413e935e4d2 100644 --- a/spec/models/form_submission_attempt_spec.rb +++ b/spec/models/form_submission_attempt_spec.rb @@ -22,7 +22,6 @@ context 'transitioning to a failure state' do let(:notification_type) { :error } - let(:vanotify_client) { instance_double(VaNotify::Service) } it 'transitions to a failure state' do form_submission_attempt = create(:form_submission_attempt) @@ -63,8 +62,8 @@ end context 'is a form526_form4142 form' do + let(:vanotify_client) { instance_double(VaNotify::Service) } let!(:email_klass) { EVSS::DisabilityCompensationForm::Form4142DocumentUploadFailureEmail } - let(:mocked_notification_service) { instance_double(VaNotify::Service) } let!(:form526_submission) { create(:form526_submission) } let!(:form526_form4142_form_submission) do create(:form_submission, saved_claim_id: form526_submission.saved_claim.id, @@ -78,8 +77,8 @@ Flipper.enable(CentralMail::SubmitForm4142Job::POLLING_FLIPPER_KEY) Flipper.enable(CentralMail::SubmitForm4142Job::POLLED_FAILURE_EMAIL) - allow(VaNotify::Service).to receive(:new).and_return(mocked_notification_service) - allow(mocked_notification_service).to receive(:send_email).and_return(true) + allow(VaNotify::Service).to receive(:new).and_return(vanotify_client) + allow(vanotify_client).to receive(:send_email).and_return(true) with_settings(Settings.vanotify.services.benefits_disability, { api_key: 'test_service_api_key' }) do expect do From 039d1ff39efb6c8def0b0d35f0c1e1a545fb7dfb Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Mon, 21 Oct 2024 10:29:50 -0400 Subject: [PATCH 30/58] fixing tests --- spec/sidekiq/central_mail/submit_form4142_job_spec.rb | 4 ++-- spec/support/matchers/negated_matchers.rb | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/spec/sidekiq/central_mail/submit_form4142_job_spec.rb b/spec/sidekiq/central_mail/submit_form4142_job_spec.rb index dc0852b1160..d04cd2d34a4 100644 --- a/spec/sidekiq/central_mail/submit_form4142_job_spec.rb +++ b/spec/sidekiq/central_mail/submit_form4142_job_spec.rb @@ -230,8 +230,8 @@ described_class.drain end end - end.not.to change(FormSubmission, :count) - .and.not_to change(FormSubmissionAttempt, :count) + end.to not_change(FormSubmission, :count) + .and not_change(FormSubmissionAttempt, :count) end it 'submits successfully' do diff --git a/spec/support/matchers/negated_matchers.rb b/spec/support/matchers/negated_matchers.rb index 7733affd65d..00e76580d8b 100644 --- a/spec/support/matchers/negated_matchers.rb +++ b/spec/support/matchers/negated_matchers.rb @@ -2,3 +2,4 @@ RSpec::Matchers.define_negated_matcher :not_trigger_statsd_increment, :trigger_statsd_increment RSpec::Matchers.define_negated_matcher :not_trigger_statsd_measure, :trigger_statsd_measure +RSpec::Matchers.define_negated_matcher :not_change, :change From 3933f1b4e1d431e09a99bc1feb93cf90e8389c67 Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Mon, 21 Oct 2024 12:53:09 -0400 Subject: [PATCH 31/58] Adding ZSF increments --- app/models/form_submission_attempt.rb | 41 ++++++++++++++++++--------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/app/models/form_submission_attempt.rb b/app/models/form_submission_attempt.rb index ede73855cf4..66553d0066a 100644 --- a/app/models/form_submission_attempt.rb +++ b/app/models/form_submission_attempt.rb @@ -25,20 +25,33 @@ class FormSubmissionAttempt < ApplicationRecord event :fail do after do - log_info = { form_submission_id:, - benefits_intake_uuid: form_submission&.benefits_intake_uuid, - form_type: form_submission&.form_type } - if should_send_simple_forms_email - Rails.logger.info('Preparing to send Form Submission Attempt error email', log_info) - simple_forms_enqueue_result_email(:error) - elsif should_send_form526_form4142_email - # Do not love hard coding this in here like this. - # Hoping to refactor this at somepoint to better support various emailing on arbitrary or inherited classes - form526_submission_id = Form526Submission.find_by(saved_claim_id:).id - Rails.logger.info('Queuing Form526:Form4142 failure email to VaNotify', - log_info.merge({ form526_submission_id: })) - jid = EVSS::DisabilityCompensationForm::Form4142DocumentUploadFailureEmail.perform_async form526_submission_id - Rails.logger.info('Queuing Form526:Form4142 failure email to VaNotify completed', log_info.merge({ jid: })) + begin + zsf_service = 'simple-forms-api' # get from simple forms team + zsf_function = 'queue failure email' + user_uuid = form_submission.user_account.id + log_info = { form_submission_id:, + benefits_intake_uuid: form_submission&.benefits_intake_uuid, + form_type: form_submission&.form_type, + user_uuid: user_uuid + } + if should_send_simple_forms_email + Rails.logger.info('Preparing to send Form Submission Attempt error email', log_info) + simple_forms_enqueue_result_email(:error) + elsif should_send_form526_form4142_email + # Do not love hard coding this in here like this. + # Hoping to refactor this at somepoint to better support various emailing on arbitrary or inherited classes + zsf_service = 'disability-application' + zsf_function = 'Form 525 Flow - Form 4142 failure email queuing' + form526_submission_id = Form526Submission.find_by(saved_claim_id:).id + Rails.logger.info('Queuing Form526:Form4142 failure email to VaNotify', + log_info.merge({ form526_submission_id: })) + jid = EVSS::DisabilityCompensationForm::Form4142DocumentUploadFailureEmail.perform_async form526_submission_id + Rails.logger.info('Queuing Form526:Form4142 failure email to VaNotify completed', log_info.merge({ jid: })) + end + rescue => e + cl = caller_locations.first + call_location = ZeroSilentFailures::Monitor::CallLocation.new(zsf_function, cl.path, cl.lineno) + ZeroSilentFailures::Monitor.new(zsf_service).log_silent_failure(log_info, user_uuid, call_location:) end end From a6646361de2e40f218887004f39846991b82ba80 Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Mon, 21 Oct 2024 12:54:48 -0400 Subject: [PATCH 32/58] rubocop --- app/models/form_submission_attempt.rb | 51 +++++++++++++-------------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/app/models/form_submission_attempt.rb b/app/models/form_submission_attempt.rb index 66553d0066a..65811a819ac 100644 --- a/app/models/form_submission_attempt.rb +++ b/app/models/form_submission_attempt.rb @@ -25,34 +25,31 @@ class FormSubmissionAttempt < ApplicationRecord event :fail do after do - begin - zsf_service = 'simple-forms-api' # get from simple forms team - zsf_function = 'queue failure email' - user_uuid = form_submission.user_account.id - log_info = { form_submission_id:, - benefits_intake_uuid: form_submission&.benefits_intake_uuid, - form_type: form_submission&.form_type, - user_uuid: user_uuid - } - if should_send_simple_forms_email - Rails.logger.info('Preparing to send Form Submission Attempt error email', log_info) - simple_forms_enqueue_result_email(:error) - elsif should_send_form526_form4142_email - # Do not love hard coding this in here like this. - # Hoping to refactor this at somepoint to better support various emailing on arbitrary or inherited classes - zsf_service = 'disability-application' - zsf_function = 'Form 525 Flow - Form 4142 failure email queuing' - form526_submission_id = Form526Submission.find_by(saved_claim_id:).id - Rails.logger.info('Queuing Form526:Form4142 failure email to VaNotify', - log_info.merge({ form526_submission_id: })) - jid = EVSS::DisabilityCompensationForm::Form4142DocumentUploadFailureEmail.perform_async form526_submission_id - Rails.logger.info('Queuing Form526:Form4142 failure email to VaNotify completed', log_info.merge({ jid: })) - end - rescue => e - cl = caller_locations.first - call_location = ZeroSilentFailures::Monitor::CallLocation.new(zsf_function, cl.path, cl.lineno) - ZeroSilentFailures::Monitor.new(zsf_service).log_silent_failure(log_info, user_uuid, call_location:) + zsf_service = 'simple-forms-api' # get from simple forms team + zsf_function = 'queue failure email' + user_uuid = form_submission.user_account.id + log_info = { form_submission_id:, + benefits_intake_uuid: form_submission&.benefits_intake_uuid, + form_type: form_submission&.form_type, + user_uuid: user_uuid } + if should_send_simple_forms_email + Rails.logger.info('Preparing to send Form Submission Attempt error email', log_info) + simple_forms_enqueue_result_email(:error) + elsif should_send_form526_form4142_email + # Do not love hard coding this in here like this. + # Hoping to refactor this at somepoint to better support various emailing on arbitrary or inherited classes + zsf_service = 'disability-application' + zsf_function = 'Form 525 Flow - Form 4142 failure email queuing' + form526_submission_id = Form526Submission.find_by(saved_claim_id:).id + Rails.logger.info('Queuing Form526:Form4142 failure email to VaNotify', + log_info.merge({ form526_submission_id: })) + jid = EVSS::DisabilityCompensationForm::Form4142DocumentUploadFailureEmail.perform_async form526_submission_id + Rails.logger.info('Queuing Form526:Form4142 failure email to VaNotify completed', log_info.merge({ jid: })) end + rescue + cl = caller_locations.first + call_location = ZeroSilentFailures::Monitor::CallLocation.new(zsf_function, cl.path, cl.lineno) + ZeroSilentFailures::Monitor.new(zsf_service).log_silent_failure(log_info, user_uuid, call_location:) end transitions from: :pending, to: :failure From 035b49747bcdb9fdccbd3f34e41136b0fb634dda Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Mon, 21 Oct 2024 13:06:57 -0400 Subject: [PATCH 33/58] rubocop --- app/models/form_submission_attempt.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/form_submission_attempt.rb b/app/models/form_submission_attempt.rb index 65811a819ac..5813ccf334b 100644 --- a/app/models/form_submission_attempt.rb +++ b/app/models/form_submission_attempt.rb @@ -46,10 +46,12 @@ class FormSubmissionAttempt < ApplicationRecord jid = EVSS::DisabilityCompensationForm::Form4142DocumentUploadFailureEmail.perform_async form526_submission_id Rails.logger.info('Queuing Form526:Form4142 failure email to VaNotify completed', log_info.merge({ jid: })) end - rescue + rescue => e cl = caller_locations.first call_location = ZeroSilentFailures::Monitor::CallLocation.new(zsf_function, cl.path, cl.lineno) - ZeroSilentFailures::Monitor.new(zsf_service).log_silent_failure(log_info, user_uuid, call_location:) + error_hash = { error_class: e.class, error_message: e.message } + ZeroSilentFailures::Monitor.new(zsf_service).log_silent_failure(log_info.merge(error_hash), user_uuid, + call_location:) end transitions from: :pending, to: :failure From 21575f9c99177f74e087ea4d977a03c4d08dd351 Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Mon, 21 Oct 2024 13:57:06 -0400 Subject: [PATCH 34/58] Adding email job statsD --- app/models/form_submission_attempt.rb | 8 ++-- .../form4142_document_upload_failure_email.rb | 38 ++++++++++++------- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/app/models/form_submission_attempt.rb b/app/models/form_submission_attempt.rb index 5813ccf334b..ab326692682 100644 --- a/app/models/form_submission_attempt.rb +++ b/app/models/form_submission_attempt.rb @@ -25,13 +25,15 @@ class FormSubmissionAttempt < ApplicationRecord event :fail do after do - zsf_service = 'simple-forms-api' # get from simple forms team - zsf_function = 'queue failure email' user_uuid = form_submission.user_account.id + form_type = form_submission&.form_type log_info = { form_submission_id:, benefits_intake_uuid: form_submission&.benefits_intake_uuid, - form_type: form_submission&.form_type, + form_type:, user_uuid: user_uuid } + + zsf_service = 'veteran-facing-forms' + zsf_function = "#{form_id} form submission to Lighthouse" if should_send_simple_forms_email Rails.logger.info('Preparing to send Form Submission Attempt error email', log_info) simple_forms_enqueue_result_email(:error) diff --git a/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb b/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb index 779ca4807d4..ed31beb1f62 100644 --- a/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb +++ b/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb @@ -6,6 +6,9 @@ module EVSS module DisabilityCompensationForm class Form4142DocumentUploadFailureEmail < Job STATSD_METRIC_PREFIX = 'api.form_526.veteran_notifications.form4142_upload_failure_email' + ZSF_DD_TAG_FUNCTION = 'Form 525 Flow - Form 4142 failure email sending' + ZSF_DD_TAG_SERVICE = 'disability-application' + # retry for one day sidekiq_options retry: 14 @@ -17,6 +20,23 @@ class Form4142DocumentUploadFailureEmail < Job timestamp = Time.now.utc form526_submission_id = msg['args'].first + Rails.logger.warn( + 'Form4142DocumentUploadFailureEmail retries exhausted', + { + job_id:, + timestamp:, + form526_submission_id:, + error_class:, + error_message: + } + ) + + StatsD.increment("#{STATSD_METRIC_PREFIX}.exhausted") + cl = caller_locations.first + call_location = ZeroSilentFailures::Monitor::CallLocation.new(ZSF_DD_TAG_FUNCTION, cl.path, cl.lineno) + ZeroSilentFailures::Monitor.new(zsf_service).log_silent_failure(log_info, user_uuid, + call_location:) + # Job status records are upserted in the JobTracker module # when the retryable_error_handler is called form_job_status = Form526JobStatus.find_by(job_id:) @@ -28,23 +48,11 @@ class Form4142DocumentUploadFailureEmail < Job form526_submission_id: } } + form_job_status.update( status: Form526JobStatus::STATUS[:exhausted], bgjob_errors: bgjob_errors.merge(new_error) ) - - Rails.logger.warn( - 'Form4142DocumentUploadFailureEmail retries exhausted', - { - job_id:, - timestamp:, - form526_submission_id:, - error_class:, - error_message: - } - ) - - StatsD.increment("#{STATSD_METRIC_PREFIX}.exhausted") rescue => e Rails.logger.error( 'Failure in Form4142DocumentUploadFailureEmail#sidekiq_retries_exhausted', @@ -104,6 +112,10 @@ def log_mailer_dispatch(form526_submission_id) } ) + cl = caller_locations.first + call_location = ZeroSilentFailures::Monitor::CallLocation.new(ZSF_DD_TAG_FUNCTION, cl.path, cl.lineno) + ZeroSilentFailures::Monitor.new(ZSF_DD_TAG_SERVICE).log_silent_failure(log_info, user_uuid, + call_location:) StatsD.increment("#{STATSD_METRIC_PREFIX}.success") end From 742c7345dba77225e6c30d16c0228a3f0a14ebf8 Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Mon, 21 Oct 2024 14:45:37 -0400 Subject: [PATCH 35/58] Adding service constant --- app/models/form526_submission.rb | 1 + app/models/form_submission_attempt.rb | 15 +++++++++------ .../form4142_document_upload_failure_email.rb | 12 +++++------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/app/models/form526_submission.rb b/app/models/form526_submission.rb index 232981f126c..3a0dc71cd1a 100644 --- a/app/models/form526_submission.rb +++ b/app/models/form526_submission.rb @@ -77,6 +77,7 @@ class Form526Submission < ApplicationRecord # MAX_PENDING_TIME aligns with the farthest out expectation given in the LH BI docs, # plus 1 week to accomodate for edge cases and our sidekiq jobs MAX_PENDING_TIME = 3.weeks + ZSF_DD_TAG_SERVICE = 'disability-application' # used to track in APMs between systems such as Lighthouse # example: can be used as a search parameter in Datadog diff --git a/app/models/form_submission_attempt.rb b/app/models/form_submission_attempt.rb index ab326692682..0cd68dda0df 100644 --- a/app/models/form_submission_attempt.rb +++ b/app/models/form_submission_attempt.rb @@ -31,8 +31,6 @@ class FormSubmissionAttempt < ApplicationRecord benefits_intake_uuid: form_submission&.benefits_intake_uuid, form_type:, user_uuid: user_uuid } - - zsf_service = 'veteran-facing-forms' zsf_function = "#{form_id} form submission to Lighthouse" if should_send_simple_forms_email Rails.logger.info('Preparing to send Form Submission Attempt error email', log_info) @@ -40,7 +38,6 @@ class FormSubmissionAttempt < ApplicationRecord elsif should_send_form526_form4142_email # Do not love hard coding this in here like this. # Hoping to refactor this at somepoint to better support various emailing on arbitrary or inherited classes - zsf_service = 'disability-application' zsf_function = 'Form 525 Flow - Form 4142 failure email queuing' form526_submission_id = Form526Submission.find_by(saved_claim_id:).id Rails.logger.info('Queuing Form526:Form4142 failure email to VaNotify', @@ -51,9 +48,15 @@ class FormSubmissionAttempt < ApplicationRecord rescue => e cl = caller_locations.first call_location = ZeroSilentFailures::Monitor::CallLocation.new(zsf_function, cl.path, cl.lineno) - error_hash = { error_class: e.class, error_message: e.message } - ZeroSilentFailures::Monitor.new(zsf_service).log_silent_failure(log_info.merge(error_hash), user_uuid, - call_location:) + ZeroSilentFailures::Monitor.new(Form526Submission::ZSF_DD_TAG_SERVICE) + .log_silent_failure( + log_info.merge({ + error_class: e.class, + error_message: e.message + }), + user_uuid, + call_location: + ) end transitions from: :pending, to: :failure diff --git a/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb b/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb index ed31beb1f62..a19f058363d 100644 --- a/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb +++ b/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb @@ -6,9 +6,7 @@ module EVSS module DisabilityCompensationForm class Form4142DocumentUploadFailureEmail < Job STATSD_METRIC_PREFIX = 'api.form_526.veteran_notifications.form4142_upload_failure_email' - ZSF_DD_TAG_FUNCTION = 'Form 525 Flow - Form 4142 failure email sending' - ZSF_DD_TAG_SERVICE = 'disability-application' - + ZSF_DD_TAG_FUNCTION = 'Form 525 Flow - Form 4142 failure email sending' # retry for one day sidekiq_options retry: 14 @@ -34,8 +32,8 @@ class Form4142DocumentUploadFailureEmail < Job StatsD.increment("#{STATSD_METRIC_PREFIX}.exhausted") cl = caller_locations.first call_location = ZeroSilentFailures::Monitor::CallLocation.new(ZSF_DD_TAG_FUNCTION, cl.path, cl.lineno) - ZeroSilentFailures::Monitor.new(zsf_service).log_silent_failure(log_info, user_uuid, - call_location:) + ZeroSilentFailures::Monitor.new(Form526Submission::ZSF_DD_TAG_SERVICE).log_silent_failure(log_info, user_uuid, + call_location:) # Job status records are upserted in the JobTracker module # when the retryable_error_handler is called @@ -114,8 +112,8 @@ def log_mailer_dispatch(form526_submission_id) cl = caller_locations.first call_location = ZeroSilentFailures::Monitor::CallLocation.new(ZSF_DD_TAG_FUNCTION, cl.path, cl.lineno) - ZeroSilentFailures::Monitor.new(ZSF_DD_TAG_SERVICE).log_silent_failure(log_info, user_uuid, - call_location:) + ZeroSilentFailures::Monitor.new(Form526Submission::ZSF_DD_TAG_SERVICE).log_silent_failure(log_info, user_uuid, + call_location:) StatsD.increment("#{STATSD_METRIC_PREFIX}.success") end From 64630b4f064e592b7cdd225e389320426253d486 Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Mon, 21 Oct 2024 14:53:42 -0400 Subject: [PATCH 36/58] Fixing form num --- app/models/form_submission_attempt.rb | 2 +- .../form4142_document_upload_failure_email.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/form_submission_attempt.rb b/app/models/form_submission_attempt.rb index 0cd68dda0df..0438bb631b9 100644 --- a/app/models/form_submission_attempt.rb +++ b/app/models/form_submission_attempt.rb @@ -38,7 +38,7 @@ class FormSubmissionAttempt < ApplicationRecord elsif should_send_form526_form4142_email # Do not love hard coding this in here like this. # Hoping to refactor this at somepoint to better support various emailing on arbitrary or inherited classes - zsf_function = 'Form 525 Flow - Form 4142 failure email queuing' + zsf_function = 'Form 526 Flow - Form 4142 failure email queuing' form526_submission_id = Form526Submission.find_by(saved_claim_id:).id Rails.logger.info('Queuing Form526:Form4142 failure email to VaNotify', log_info.merge({ form526_submission_id: })) diff --git a/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb b/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb index a19f058363d..d030f379b97 100644 --- a/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb +++ b/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb @@ -6,7 +6,7 @@ module EVSS module DisabilityCompensationForm class Form4142DocumentUploadFailureEmail < Job STATSD_METRIC_PREFIX = 'api.form_526.veteran_notifications.form4142_upload_failure_email' - ZSF_DD_TAG_FUNCTION = 'Form 525 Flow - Form 4142 failure email sending' + ZSF_DD_TAG_FUNCTION = 'Form 526 Flow - Form 4142 failure email sending' # retry for one day sidekiq_options retry: 14 From 2418f161bc7d28512b644994c062d64ab23c41fd Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Mon, 21 Oct 2024 15:15:39 -0400 Subject: [PATCH 37/58] Rubocop --- .../form4142_document_upload_failure_email.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb b/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb index d030f379b97..76dda15d2a7 100644 --- a/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb +++ b/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb @@ -112,8 +112,8 @@ def log_mailer_dispatch(form526_submission_id) cl = caller_locations.first call_location = ZeroSilentFailures::Monitor::CallLocation.new(ZSF_DD_TAG_FUNCTION, cl.path, cl.lineno) - ZeroSilentFailures::Monitor.new(Form526Submission::ZSF_DD_TAG_SERVICE).log_silent_failure(log_info, user_uuid, - call_location:) + ZeroSilentFailures::Monitor.new(Form526Submission::ZSF_DD_TAG_SERVICE) + .log_silent_failure_avoided(log_info, user_uuid, call_location:) StatsD.increment("#{STATSD_METRIC_PREFIX}.success") end From 6fabd4f66cbb5d8a43574331bf5a0fbcdc99938c Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Mon, 21 Oct 2024 15:23:36 -0400 Subject: [PATCH 38/58] Removing lines to appease CI/CD --- app/models/form_submission_attempt.rb | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/app/models/form_submission_attempt.rb b/app/models/form_submission_attempt.rb index 0438bb631b9..ada37920aa1 100644 --- a/app/models/form_submission_attempt.rb +++ b/app/models/form_submission_attempt.rb @@ -27,17 +27,13 @@ class FormSubmissionAttempt < ApplicationRecord after do user_uuid = form_submission.user_account.id form_type = form_submission&.form_type - log_info = { form_submission_id:, - benefits_intake_uuid: form_submission&.benefits_intake_uuid, - form_type:, + log_info = { form_submission_id:, benefits_intake_uuid: form_submission&.benefits_intake_uuid, form_type:, user_uuid: user_uuid } zsf_function = "#{form_id} form submission to Lighthouse" if should_send_simple_forms_email Rails.logger.info('Preparing to send Form Submission Attempt error email', log_info) simple_forms_enqueue_result_email(:error) elsif should_send_form526_form4142_email - # Do not love hard coding this in here like this. - # Hoping to refactor this at somepoint to better support various emailing on arbitrary or inherited classes zsf_function = 'Form 526 Flow - Form 4142 failure email queuing' form526_submission_id = Form526Submission.find_by(saved_claim_id:).id Rails.logger.info('Queuing Form526:Form4142 failure email to VaNotify', @@ -50,10 +46,7 @@ class FormSubmissionAttempt < ApplicationRecord call_location = ZeroSilentFailures::Monitor::CallLocation.new(zsf_function, cl.path, cl.lineno) ZeroSilentFailures::Monitor.new(Form526Submission::ZSF_DD_TAG_SERVICE) .log_silent_failure( - log_info.merge({ - error_class: e.class, - error_message: e.message - }), + log_info.merge({ error_class: e.class, error_message: e.message }), user_uuid, call_location: ) From f15b91887990c9f802cd5628cecd14315861c88d Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Tue, 22 Oct 2024 09:10:44 -0400 Subject: [PATCH 39/58] Adding in ZeroSilentFailure Stuff --- .../form4142_document_upload_failure_email.rb | 45 +++++++++++-------- ...4142_document_upload_failure_email_spec.rb | 4 ++ 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb b/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb index 76dda15d2a7..82a15261b89 100644 --- a/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb +++ b/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'va_notify/service' +require 'zero_silent_failures/monitor' module EVSS module DisabilityCompensationForm @@ -18,21 +19,25 @@ class Form4142DocumentUploadFailureEmail < Job timestamp = Time.now.utc form526_submission_id = msg['args'].first + log_info = { + job_id:, + timestamp:, + form526_submission_id:, + error_class:, + error_message: + } + Rails.logger.warn( 'Form4142DocumentUploadFailureEmail retries exhausted', - { - job_id:, - timestamp:, - form526_submission_id:, - error_class:, - error_message: - } + log_info ) StatsD.increment("#{STATSD_METRIC_PREFIX}.exhausted") cl = caller_locations.first call_location = ZeroSilentFailures::Monitor::CallLocation.new(ZSF_DD_TAG_FUNCTION, cl.path, cl.lineno) - ZeroSilentFailures::Monitor.new(Form526Submission::ZSF_DD_TAG_SERVICE).log_silent_failure(log_info, user_uuid, + # nil user_uuid + # we could get it but that introduces more failure potential in what is supposed ot be a last resort + ZeroSilentFailures::Monitor.new(Form526Submission::ZSF_DD_TAG_SERVICE).log_silent_failure(log_info, nil, call_location:) # Job status records are upserted in the JobTracker module @@ -77,7 +82,7 @@ def perform(form526_submission_id) first_name = form526_submission.get_first_name date_submitted = form526_submission.format_creation_time_for_mailers - @notify_client.send_email( + notify_response = @notify_client.send_email( email_address:, template_id: mailer_template_id, personalisation: { @@ -86,7 +91,7 @@ def perform(form526_submission_id) } ) - log_mailer_dispatch(form526_submission_id) + log_mailer_dispatch(form526_submission_id, notify_response) end rescue => e retryable_error_handler(e) @@ -101,19 +106,21 @@ def retryable_error_handler(error) raise error end - def log_mailer_dispatch(form526_submission_id) - Rails.logger.info( - 'Form4142DocumentUploadFailureEmail notification dispatched', - { - form526_submission_id:, - timestamp: Time.now.utc - } - ) + def log_mailer_dispatch(form526_submission_id, email_response = {}) + log_info = { + form526_submission_id:, + timestamp: Time.now.utc + } + Rails.logger.info('Form4142DocumentUploadFailureEmail notification dispatched', log_info) cl = caller_locations.first call_location = ZeroSilentFailures::Monitor::CallLocation.new(ZSF_DD_TAG_FUNCTION, cl.path, cl.lineno) ZeroSilentFailures::Monitor.new(Form526Submission::ZSF_DD_TAG_SERVICE) - .log_silent_failure_avoided(log_info, user_uuid, call_location:) + .log_silent_failure_avoided( + log_info.merge(email_confirmation_id: email_response&.id), + nil, + call_location: + ) StatsD.increment("#{STATSD_METRIC_PREFIX}.success") end diff --git a/spec/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email_spec.rb b/spec/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email_spec.rb index 58a5fe2ee4e..669ffa5cb94 100644 --- a/spec/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email_spec.rb +++ b/spec/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email_spec.rb @@ -53,6 +53,7 @@ it 'logs to the Rails logger' do allow(Rails.logger).to receive(:info) + exhaustion_time = Time.new(1985, 10, 26).utc Timecop.freeze(exhaustion_time) do @@ -128,6 +129,9 @@ expect(StatsD).to receive(:increment).with( 'api.form_526.veteran_notifications.form4142_upload_failure_email.exhausted' ) + expect(StatsD).to receive(:increment).with('silent_failure', + tags: ['service:disability-application', + 'function:Form 526 Flow - Form 4142 failure email sending']) end expect(form526_job_status.reload.status).to eq(Form526JobStatus::STATUS[:exhausted]) From a40c3cdb000c762e728bcacd1471529a9e5fd02a Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Tue, 22 Oct 2024 09:20:48 -0400 Subject: [PATCH 40/58] Truing up with flippers removed upstream --- config/features.yml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/config/features.yml b/config/features.yml index 9a7bb83513a..5a3b99cef00 100644 --- a/config/features.yml +++ b/config/features.yml @@ -440,14 +440,6 @@ features: actor_type: user description: enables failure email when explicit failure is detected downstream enable_in_development: true - disability_526_classifier_new_claims: - actor_type: user - description: enables sending new 526-ez claims to VRO Contention Classification service for more accurate classification entry. - enable_in_development: true - disability_526_classifier_multi_contention: - actor_type: user - description: enables submitting multi-contention (in addition to single-contention) 526ez claims to VRO Contention Classification service for more accurate classification entry. - enable_in_development: true contention_classification_claim_linker: actor_type: user description: enables sending 526 claim id and vbms submitted claim id to Contention Classification service for linking/monitoring. From e88bc1514fc0a9f4002811584d32ee67c2f81016 Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Tue, 22 Oct 2024 09:41:19 -0400 Subject: [PATCH 41/58] Trying to cull lines to appease the line-counter --- .../form4142_document_upload_failure_email.rb | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb b/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb index 82a15261b89..e5ba9b6b39b 100644 --- a/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb +++ b/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb @@ -19,13 +19,7 @@ class Form4142DocumentUploadFailureEmail < Job timestamp = Time.now.utc form526_submission_id = msg['args'].first - log_info = { - job_id:, - timestamp:, - form526_submission_id:, - error_class:, - error_message: - } + log_info = { job_id:, timestamp:, form526_submission_id:, error_class:, error_message: } Rails.logger.warn( 'Form4142DocumentUploadFailureEmail retries exhausted', @@ -35,8 +29,6 @@ class Form4142DocumentUploadFailureEmail < Job StatsD.increment("#{STATSD_METRIC_PREFIX}.exhausted") cl = caller_locations.first call_location = ZeroSilentFailures::Monitor::CallLocation.new(ZSF_DD_TAG_FUNCTION, cl.path, cl.lineno) - # nil user_uuid - # we could get it but that introduces more failure potential in what is supposed ot be a last resort ZeroSilentFailures::Monitor.new(Form526Submission::ZSF_DD_TAG_SERVICE).log_silent_failure(log_info, nil, call_location:) @@ -107,10 +99,7 @@ def retryable_error_handler(error) end def log_mailer_dispatch(form526_submission_id, email_response = {}) - log_info = { - form526_submission_id:, - timestamp: Time.now.utc - } + log_info = { form526_submission_id:, timestamp: Time.now.utc } Rails.logger.info('Form4142DocumentUploadFailureEmail notification dispatched', log_info) cl = caller_locations.first From 404d8866152ae11f34f5f1f5b9c015efd29430a2 Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Tue, 22 Oct 2024 13:08:27 -0400 Subject: [PATCH 42/58] Addressing PR comments --- app/models/form_submission_attempt.rb | 4 ++-- .../form4142_document_upload_failure_email.rb | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/app/models/form_submission_attempt.rb b/app/models/form_submission_attempt.rb index ada37920aa1..78f427429a8 100644 --- a/app/models/form_submission_attempt.rb +++ b/app/models/form_submission_attempt.rb @@ -25,8 +25,8 @@ class FormSubmissionAttempt < ApplicationRecord event :fail do after do - user_uuid = form_submission.user_account.id - form_type = form_submission&.form_type + user_uuid = form_submission.user_account_id + form_type = form_submission.form_type log_info = { form_submission_id:, benefits_intake_uuid: form_submission&.benefits_intake_uuid, form_type:, user_uuid: user_uuid } zsf_function = "#{form_id} form submission to Lighthouse" diff --git a/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb b/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb index e5ba9b6b39b..202bbcc944e 100644 --- a/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb +++ b/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb @@ -29,8 +29,7 @@ class Form4142DocumentUploadFailureEmail < Job StatsD.increment("#{STATSD_METRIC_PREFIX}.exhausted") cl = caller_locations.first call_location = ZeroSilentFailures::Monitor::CallLocation.new(ZSF_DD_TAG_FUNCTION, cl.path, cl.lineno) - ZeroSilentFailures::Monitor.new(Form526Submission::ZSF_DD_TAG_SERVICE).log_silent_failure(log_info, nil, - call_location:) + zsf_monitor.log_silent_failure(log_info, nil, call_location:) # Job status records are upserted in the JobTracker module # when the retryable_error_handler is called @@ -64,6 +63,10 @@ class Form4142DocumentUploadFailureEmail < Job raise e end + def zsf_monitor + @zsf_monitor ||= ZeroSilentFailures::Monitor.new(Form526Submission::ZSF_DD_TAG_SERVICE) + end + def perform(form526_submission_id) form526_submission = Form526Submission.find(form526_submission_id) @@ -104,12 +107,11 @@ def log_mailer_dispatch(form526_submission_id, email_response = {}) cl = caller_locations.first call_location = ZeroSilentFailures::Monitor::CallLocation.new(ZSF_DD_TAG_FUNCTION, cl.path, cl.lineno) - ZeroSilentFailures::Monitor.new(Form526Submission::ZSF_DD_TAG_SERVICE) - .log_silent_failure_avoided( - log_info.merge(email_confirmation_id: email_response&.id), - nil, - call_location: - ) + zsf_monitor.log_silent_failure_avoided( + log_info.merge(email_confirmation_id: email_response&.id), + nil, + call_location: + ) StatsD.increment("#{STATSD_METRIC_PREFIX}.success") end From fee21cb1daf438aec1afb69be9ceecce9b49021c Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Tue, 22 Oct 2024 13:10:32 -0400 Subject: [PATCH 43/58] Correcting wrong variable --- app/models/form_submission_attempt.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/form_submission_attempt.rb b/app/models/form_submission_attempt.rb index 78f427429a8..f970cd2ba29 100644 --- a/app/models/form_submission_attempt.rb +++ b/app/models/form_submission_attempt.rb @@ -29,7 +29,7 @@ class FormSubmissionAttempt < ApplicationRecord form_type = form_submission.form_type log_info = { form_submission_id:, benefits_intake_uuid: form_submission&.benefits_intake_uuid, form_type:, user_uuid: user_uuid } - zsf_function = "#{form_id} form submission to Lighthouse" + zsf_function = "#{form_type} form submission to Lighthouse" if should_send_simple_forms_email Rails.logger.info('Preparing to send Form Submission Attempt error email', log_info) simple_forms_enqueue_result_email(:error) From c81a8601f2adab6f6cdb3142d679f961d044af78 Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Tue, 22 Oct 2024 13:19:18 -0400 Subject: [PATCH 44/58] Moving around logging var --- app/sidekiq/central_mail/submit_form4142_job.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/sidekiq/central_mail/submit_form4142_job.rb b/app/sidekiq/central_mail/submit_form4142_job.rb index 666cceec639..6a42b4f933f 100644 --- a/app/sidekiq/central_mail/submit_form4142_job.rb +++ b/app/sidekiq/central_mail/submit_form4142_job.rb @@ -146,16 +146,16 @@ def payload_hash(lighthouse_service_location) end def upload_to_lighthouse + log_info = { benefits_intake_uuid: lighthouse_service.uuid, submission_id: @submission_id } + Rails.logger.info( 'Successful Form4142 Upload Intake UUID aquired from Lighthouse', - { benefits_intake_uuid: lighthouse_service.uuid, submission_id: @submission_id } + log_info ) payload = payload_hash(lighthouse_service.location) lighthouse_service.upload_doc(**payload) - log_info = { benefits_intake_uuid: lighthouse_service.uuid, submission_id: @submission_id } - if Flipper.enabled?(POLLING_FLIPPER_KEY) form526_submission = Form526Submission.find(@submission_id) form_submission = FormSubmission.create( From 0d87bc5c864399a441cb4fe70519a926687ff773 Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Tue, 22 Oct 2024 13:41:21 -0400 Subject: [PATCH 45/58] Making a var a constant instead --- app/models/form_submission_attempt.rb | 2 +- app/sidekiq/central_mail/submit_form4142_job.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/form_submission_attempt.rb b/app/models/form_submission_attempt.rb index f970cd2ba29..bed942a600b 100644 --- a/app/models/form_submission_attempt.rb +++ b/app/models/form_submission_attempt.rb @@ -34,7 +34,7 @@ class FormSubmissionAttempt < ApplicationRecord Rails.logger.info('Preparing to send Form Submission Attempt error email', log_info) simple_forms_enqueue_result_email(:error) elsif should_send_form526_form4142_email - zsf_function = 'Form 526 Flow - Form 4142 failure email queuing' + zsf_function = CentralMail::SubmitForm4142Job::FORM4142_DD_ZSF_FUNCTION form526_submission_id = Form526Submission.find_by(saved_claim_id:).id Rails.logger.info('Queuing Form526:Form4142 failure email to VaNotify', log_info.merge({ form526_submission_id: })) diff --git a/app/sidekiq/central_mail/submit_form4142_job.rb b/app/sidekiq/central_mail/submit_form4142_job.rb index 6a42b4f933f..ecd9205e31b 100644 --- a/app/sidekiq/central_mail/submit_form4142_job.rb +++ b/app/sidekiq/central_mail/submit_form4142_job.rb @@ -14,6 +14,7 @@ class SubmitForm4142Job < EVSS::DisabilityCompensationForm::Job POLLED_FAILURE_EMAIL = :disability_526_form4142_polling_record_failure_email FORM4142_FORMSUBMISSION_TYPE = "#{Form526Submission::FORM_526}_#{Form526Submission::FORM_4142}".freeze + FORM4142_DD_ZSF_FUNCTION = 'Form 526 Flow - Form 4142 failure email queuing' extend Logging::ThirdPartyTransaction::MethodWrapper # this is required to make instance variables available to logs via From 237835382ba3d4d4493efde655db348298c72d7d Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Tue, 22 Oct 2024 13:44:06 -0400 Subject: [PATCH 46/58] Making more readable --- app/models/form_submission_attempt.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/form_submission_attempt.rb b/app/models/form_submission_attempt.rb index bed942a600b..52ca5c35614 100644 --- a/app/models/form_submission_attempt.rb +++ b/app/models/form_submission_attempt.rb @@ -38,7 +38,9 @@ class FormSubmissionAttempt < ApplicationRecord form526_submission_id = Form526Submission.find_by(saved_claim_id:).id Rails.logger.info('Queuing Form526:Form4142 failure email to VaNotify', log_info.merge({ form526_submission_id: })) - jid = EVSS::DisabilityCompensationForm::Form4142DocumentUploadFailureEmail.perform_async form526_submission_id + jid = EVSS::DisabilityCompensationForm::Form4142DocumentUploadFailureEmail.perform_async( + form526_submission_id + ) Rails.logger.info('Queuing Form526:Form4142 failure email to VaNotify completed', log_info.merge({ jid: })) end rescue => e From c5dd50aea577e9fa7f02afe042cb837da87ce072 Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Tue, 22 Oct 2024 13:55:01 -0400 Subject: [PATCH 47/58] Changing instance var to regular var --- .../form4142_document_upload_failure_email.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb b/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb index 202bbcc944e..3076cef061a 100644 --- a/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb +++ b/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb @@ -71,13 +71,13 @@ def perform(form526_submission_id) form526_submission = Form526Submission.find(form526_submission_id) with_tracking('Form4142DocumentUploadFailureEmail', form526_submission.saved_claim_id, form526_submission_id) do - @notify_client ||= VaNotify::Service.new(Settings.vanotify.services.benefits_disability.api_key) + notify_client = VaNotify::Service.new(Settings.vanotify.services.benefits_disability.api_key) email_address = form526_submission.veteran_email_address first_name = form526_submission.get_first_name date_submitted = form526_submission.format_creation_time_for_mailers - notify_response = @notify_client.send_email( + notify_response = notify_client.send_email( email_address:, template_id: mailer_template_id, personalisation: { From 07ff2d9a00f24ff40b3b19204cb594b214cc1d7a Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Tue, 22 Oct 2024 13:57:32 -0400 Subject: [PATCH 48/58] Fixing typo and extra db call --- spec/models/form_submission_attempt_spec.rb | 2 +- spec/sidekiq/central_mail/submit_form4142_job_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/models/form_submission_attempt_spec.rb b/spec/models/form_submission_attempt_spec.rb index 413e935e4d2..2e5f7110fa4 100644 --- a/spec/models/form_submission_attempt_spec.rb +++ b/spec/models/form_submission_attempt_spec.rb @@ -66,7 +66,7 @@ let!(:email_klass) { EVSS::DisabilityCompensationForm::Form4142DocumentUploadFailureEmail } let!(:form526_submission) { create(:form526_submission) } let!(:form526_form4142_form_submission) do - create(:form_submission, saved_claim_id: form526_submission.saved_claim.id, + create(:form_submission, saved_claim_id: form526_submission.saved_claim_id, form_type: CentralMail::SubmitForm4142Job::FORM4142_FORMSUBMISSION_TYPE) end let!(:form_submission_attempt) do diff --git a/spec/sidekiq/central_mail/submit_form4142_job_spec.rb b/spec/sidekiq/central_mail/submit_form4142_job_spec.rb index d04cd2d34a4..39785dc1f56 100644 --- a/spec/sidekiq/central_mail/submit_form4142_job_spec.rb +++ b/spec/sidekiq/central_mail/submit_form4142_job_spec.rb @@ -221,7 +221,7 @@ expect(fs_attempt_record.pending?).to be(true) end - it 'Does not creates a form 4142 submission polling record, when disabled' do + it 'Does not create a form 4142 submission polling record, when disabled' do Flipper.disable(CentralMail::SubmitForm4142Job::POLLING_FLIPPER_KEY) expect do VCR.use_cassette('lighthouse/benefits_intake/200_lighthouse_intake_upload_location') do From f9a77e97768a18b8816cd8b9cd19c285f524e77b Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Wed, 23 Oct 2024 14:39:10 -0400 Subject: [PATCH 49/58] Resolving failed test --- app/models/form_submission_attempt.rb | 32 +++++++++---------- .../form4142_document_upload_failure_email.rb | 11 ++++--- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/app/models/form_submission_attempt.rb b/app/models/form_submission_attempt.rb index 52ca5c35614..8f67ded9cc6 100644 --- a/app/models/form_submission_attempt.rb +++ b/app/models/form_submission_attempt.rb @@ -33,15 +33,22 @@ class FormSubmissionAttempt < ApplicationRecord if should_send_simple_forms_email Rails.logger.info('Preparing to send Form Submission Attempt error email', log_info) simple_forms_enqueue_result_email(:error) - elsif should_send_form526_form4142_email - zsf_function = CentralMail::SubmitForm4142Job::FORM4142_DD_ZSF_FUNCTION - form526_submission_id = Form526Submission.find_by(saved_claim_id:).id - Rails.logger.info('Queuing Form526:Form4142 failure email to VaNotify', - log_info.merge({ form526_submission_id: })) - jid = EVSS::DisabilityCompensationForm::Form4142DocumentUploadFailureEmail.perform_async( - form526_submission_id - ) - Rails.logger.info('Queuing Form526:Form4142 failure email to VaNotify completed', log_info.merge({ jid: })) + elsif form_submission.form_type == CentralMail::SubmitForm4142Job::FORM4142_FORMSUBMISSION_TYPE + if Flipper.enabled?(CentralMail::SubmitForm4142Job::POLLED_FAILURE_EMAIL) + zsf_function = CentralMail::SubmitForm4142Job::FORM4142_DD_ZSF_FUNCTION + form526_submission_id = Form526Submission.find_by(saved_claim_id:).id + Rails.logger.info('Queuing Form526:Form4142 failure email to VaNotify', + log_info.merge({ form526_submission_id: })) + jid = EVSS::DisabilityCompensationForm::Form4142DocumentUploadFailureEmail.perform_async( + form526_submission_id + ) + Rails.logger.info('Queuing Form526:Form4142 failure email to VaNotify completed', log_info.merge({ jid: })) + else + Rails.logger.info( + 'Would queue EVSS::DisabilityCompensationForm::Form4142DocumentUploadFailureEmail, but flipper is off.', + log_info + ) + end end rescue => e cl = caller_locations.first @@ -102,13 +109,6 @@ def should_send_simple_forms_email simple_forms_form_number && Flipper.enabled?(:simple_forms_email_notifications) end - def should_send_form526_form4142_email - email_klass = CentralMail::SubmitForm4142Job - email_klass_form_type = email_klass::FORM4142_FORMSUBMISSION_TYPE - email_klass_polled_failure_email_enabled = Flipper.enabled?(email_klass::POLLED_FAILURE_EMAIL) - form_submission.form_type == email_klass_form_type && email_klass_polled_failure_email_enabled - end - def simple_forms_enqueue_result_email(notification_type) raw_form_data = form_submission.form_data || '{}' form_data = JSON.parse(raw_form_data) diff --git a/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb b/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb index 3076cef061a..f66d2499233 100644 --- a/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb +++ b/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb @@ -29,7 +29,8 @@ class Form4142DocumentUploadFailureEmail < Job StatsD.increment("#{STATSD_METRIC_PREFIX}.exhausted") cl = caller_locations.first call_location = ZeroSilentFailures::Monitor::CallLocation.new(ZSF_DD_TAG_FUNCTION, cl.path, cl.lineno) - zsf_monitor.log_silent_failure(log_info, nil, call_location:) + ZeroSilentFailures::Monitor.new(Form526Submission::ZSF_DD_TAG_SERVICE).log_silent_failure(log_info, nil, + call_location:) # Job status records are upserted in the JobTracker module # when the retryable_error_handler is called @@ -63,10 +64,6 @@ class Form4142DocumentUploadFailureEmail < Job raise e end - def zsf_monitor - @zsf_monitor ||= ZeroSilentFailures::Monitor.new(Form526Submission::ZSF_DD_TAG_SERVICE) - end - def perform(form526_submission_id) form526_submission = Form526Submission.find(form526_submission_id) @@ -94,6 +91,10 @@ def perform(form526_submission_id) private + def zsf_monitor + @zsf_monitor ||= ZeroSilentFailures::Monitor.new(Form526Submission::ZSF_DD_TAG_SERVICE) + end + def retryable_error_handler(error) # Needed to log the error properly in the Sidekiq::Form526JobStatusTracker::JobTracker, # which is included near the top of this job's inheritance tree in EVSS::DisabilityCompensationForm::JobStatus From 753affdee0d223091224fcaf0dabc43adb7629b3 Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Wed, 23 Oct 2024 14:51:49 -0400 Subject: [PATCH 50/58] Fixing comment --- app/sidekiq/central_mail/submit_form4142_job.rb | 2 +- .../form4142_document_upload_failure_email.rb | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/sidekiq/central_mail/submit_form4142_job.rb b/app/sidekiq/central_mail/submit_form4142_job.rb index ecd9205e31b..b3cc46afad1 100644 --- a/app/sidekiq/central_mail/submit_form4142_job.rb +++ b/app/sidekiq/central_mail/submit_form4142_job.rb @@ -162,7 +162,7 @@ def upload_to_lighthouse form_submission = FormSubmission.create( form_type: FORM4142_FORMSUBMISSION_TYPE, # form526_form4142 benefits_intake_uuid: lighthouse_service.uuid, - form_data: '{}', # we have this already in the Form526Submission.form['form526']['form526']['form4142'] + form_data: '{}', # we have this already in the Form526Submission.form['form4142'] user_account: form526_submission.user_account, saved_claim: form526_submission.saved_claim ) diff --git a/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb b/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb index f66d2499233..47adf633f51 100644 --- a/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb +++ b/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb @@ -26,12 +26,6 @@ class Form4142DocumentUploadFailureEmail < Job log_info ) - StatsD.increment("#{STATSD_METRIC_PREFIX}.exhausted") - cl = caller_locations.first - call_location = ZeroSilentFailures::Monitor::CallLocation.new(ZSF_DD_TAG_FUNCTION, cl.path, cl.lineno) - ZeroSilentFailures::Monitor.new(Form526Submission::ZSF_DD_TAG_SERVICE).log_silent_failure(log_info, nil, - call_location:) - # Job status records are upserted in the JobTracker module # when the retryable_error_handler is called form_job_status = Form526JobStatus.find_by(job_id:) @@ -62,6 +56,12 @@ class Form4142DocumentUploadFailureEmail < Job } ) raise e + ensure + StatsD.increment("#{STATSD_METRIC_PREFIX}.exhausted") + cl = caller_locations.first + call_location = ZeroSilentFailures::Monitor::CallLocation.new(ZSF_DD_TAG_FUNCTION, cl.path, cl.lineno) + ZeroSilentFailures::Monitor.new(Form526Submission::ZSF_DD_TAG_SERVICE).log_silent_failure(log_info, nil, + call_location:) end def perform(form526_submission_id) From 06819e24677d43e51e66b94bd799c2791cd296e1 Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Wed, 23 Oct 2024 15:01:52 -0400 Subject: [PATCH 51/58] Dont want to confuse these vars --- app/models/form_submission_attempt.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/form_submission_attempt.rb b/app/models/form_submission_attempt.rb index 8f67ded9cc6..5d34fe383f4 100644 --- a/app/models/form_submission_attempt.rb +++ b/app/models/form_submission_attempt.rb @@ -25,10 +25,10 @@ class FormSubmissionAttempt < ApplicationRecord event :fail do after do - user_uuid = form_submission.user_account_id + user_account_uuid = form_submission.user_account_id form_type = form_submission.form_type log_info = { form_submission_id:, benefits_intake_uuid: form_submission&.benefits_intake_uuid, form_type:, - user_uuid: user_uuid } + user_account_uuid: } zsf_function = "#{form_type} form submission to Lighthouse" if should_send_simple_forms_email Rails.logger.info('Preparing to send Form Submission Attempt error email', log_info) @@ -56,7 +56,7 @@ class FormSubmissionAttempt < ApplicationRecord ZeroSilentFailures::Monitor.new(Form526Submission::ZSF_DD_TAG_SERVICE) .log_silent_failure( log_info.merge({ error_class: e.class, error_message: e.message }), - user_uuid, + user_account_uuid, call_location: ) end From d53e24034fda1ce7e69338fcece057abcdfb251b Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Wed, 23 Oct 2024 15:45:09 -0400 Subject: [PATCH 52/58] Fixing test --- spec/models/form_submission_attempt_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/form_submission_attempt_spec.rb b/spec/models/form_submission_attempt_spec.rb index 2e5f7110fa4..a44fb1db8f3 100644 --- a/spec/models/form_submission_attempt_spec.rb +++ b/spec/models/form_submission_attempt_spec.rb @@ -78,7 +78,7 @@ Flipper.enable(CentralMail::SubmitForm4142Job::POLLED_FAILURE_EMAIL) allow(VaNotify::Service).to receive(:new).and_return(vanotify_client) - allow(vanotify_client).to receive(:send_email).and_return(true) + allow(vanotify_client).to receive(:send_email).and_return(OpenStruct.new(id: 'some_id')) with_settings(Settings.vanotify.services.benefits_disability, { api_key: 'test_service_api_key' }) do expect do From af755fb24ebadc3d2e3258e0df84187f2ef825d8 Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Thu, 24 Oct 2024 07:51:45 -0400 Subject: [PATCH 53/58] Adding support for user account id in error message --- .../form4142_document_upload_failure_email.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb b/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb index 47adf633f51..d4870d162e9 100644 --- a/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb +++ b/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb @@ -60,8 +60,16 @@ class Form4142DocumentUploadFailureEmail < Job StatsD.increment("#{STATSD_METRIC_PREFIX}.exhausted") cl = caller_locations.first call_location = ZeroSilentFailures::Monitor::CallLocation.new(ZSF_DD_TAG_FUNCTION, cl.path, cl.lineno) - ZeroSilentFailures::Monitor.new(Form526Submission::ZSF_DD_TAG_SERVICE).log_silent_failure(log_info, nil, - call_location:) + user_account_id = begin + Form526Submission.find(form526_submission_id).user_account_id + rescue + nil + end + ZeroSilentFailures::Monitor.new(Form526Submission::ZSF_DD_TAG_SERVICE).log_silent_failure( + log_info, + user_account_id:, + call_location: + ) end def perform(form526_submission_id) @@ -110,7 +118,7 @@ def log_mailer_dispatch(form526_submission_id, email_response = {}) call_location = ZeroSilentFailures::Monitor::CallLocation.new(ZSF_DD_TAG_FUNCTION, cl.path, cl.lineno) zsf_monitor.log_silent_failure_avoided( log_info.merge(email_confirmation_id: email_response&.id), - nil, + Form526Submission.find(form526_submission_id).user_account_id, call_location: ) StatsD.increment("#{STATSD_METRIC_PREFIX}.success") From 423def313c8f755e491b85c28cbfb0f1822f981a Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Thu, 24 Oct 2024 10:39:14 -0400 Subject: [PATCH 54/58] Fixing arg --- .../form4142_document_upload_failure_email.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb b/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb index d4870d162e9..023b9a31ccd 100644 --- a/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb +++ b/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb @@ -67,7 +67,7 @@ class Form4142DocumentUploadFailureEmail < Job end ZeroSilentFailures::Monitor.new(Form526Submission::ZSF_DD_TAG_SERVICE).log_silent_failure( log_info, - user_account_id:, + user_account_id, call_location: ) end From 8bdd2ce30659db63c79ae670ee5c86b6ebe3360e Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Thu, 24 Oct 2024 12:55:23 -0400 Subject: [PATCH 55/58] extracting out this code --- app/models/form_submission_attempt.rb | 64 ++++++++++++++++----------- 1 file changed, 37 insertions(+), 27 deletions(-) diff --git a/app/models/form_submission_attempt.rb b/app/models/form_submission_attempt.rb index 99a5ae61117..17fd2e1358e 100644 --- a/app/models/form_submission_attempt.rb +++ b/app/models/form_submission_attempt.rb @@ -29,36 +29,11 @@ class FormSubmissionAttempt < ApplicationRecord form_type = form_submission.form_type log_info = { form_submission_id:, benefits_intake_uuid: form_submission&.benefits_intake_uuid, form_type:, user_account_uuid: } - zsf_function = "#{form_type} form submission to Lighthouse" if should_send_simple_forms_email - Rails.logger.info('Preparing to send Form Submission Attempt error email', log_info) - simple_forms_enqueue_result_email(:error) + simple_forms_api_email(log_info) elsif form_submission.form_type == CentralMail::SubmitForm4142Job::FORM4142_FORMSUBMISSION_TYPE - if Flipper.enabled?(CentralMail::SubmitForm4142Job::POLLED_FAILURE_EMAIL) - zsf_function = CentralMail::SubmitForm4142Job::FORM4142_DD_ZSF_FUNCTION - form526_submission_id = Form526Submission.find_by(saved_claim_id:).id - Rails.logger.info('Queuing Form526:Form4142 failure email to VaNotify', - log_info.merge({ form526_submission_id: })) - jid = EVSS::DisabilityCompensationForm::Form4142DocumentUploadFailureEmail.perform_async( - form526_submission_id - ) - Rails.logger.info('Queuing Form526:Form4142 failure email to VaNotify completed', log_info.merge({ jid: })) - else - Rails.logger.info( - 'Would queue EVSS::DisabilityCompensationForm::Form4142DocumentUploadFailureEmail, but flipper is off.', - log_info - ) - end + form_526_form4142_email(log_info) end - rescue => e - cl = caller_locations.first - call_location = ZeroSilentFailures::Monitor::CallLocation.new(zsf_function, cl.path, cl.lineno) - ZeroSilentFailures::Monitor.new(Form526Submission::ZSF_DD_TAG_SERVICE) - .log_silent_failure( - log_info.merge({ error_class: e.class, error_message: e.message }), - user_account_uuid, - call_location: - ) end transitions from: :pending, to: :failure @@ -105,6 +80,41 @@ def log_status_change private + def simple_forms_api_email(log_info) + Rails.logger.info('Preparing to send Form Submission Attempt error email', log_info) + simple_forms_enqueue_result_email(:error) + end + + def queue_form526_form4142_email(form526_submission_id, log_info) + Rails.logger.info('Queuing Form526:Form4142 failure email to VaNotify', + log_info.merge({ form526_submission_id: })) + jid = EVSS::DisabilityCompensationForm::Form4142DocumentUploadFailureEmail.perform_async( + form526_submission_id + ) + Rails.logger.info('Queuing Form526:Form4142 failure email to VaNotify completed', + log_info.merge({ jid:, form526_submission_id: })) + end + + def form526_form4142_email(log_info) + if Flipper.enabled?(CentralMail::SubmitForm4142Job::POLLED_FAILURE_EMAIL) + queue_form526_form4142_email(Form526Submission.find_by(saved_claim_id:).id, log_info) + else + Rails.logger.info( + 'Would queue EVSS::DisabilityCompensationForm::Form4142DocumentUploadFailureEmail, but flipper is off.', + log_info.merge({ form526_submission_id: }) + ) + end + rescue => e + cl = caller_locations.first + call_location = ZeroSilentFailures::Monitor::CallLocation.new( + CentralMail::SubmitForm4142Job::FORM4142_DD_ZSF_FUNCTION, cl.path, cl.lineno + ) + ZeroSilentFailures::Monitor.new(Form526Submission::ZSF_DD_TAG_SERVICE).log_silent_failure( + log_info.merge({ error_class: e.class, error_message: e.message }), + user_account_uuid, call_location: + ) + end + def should_send_simple_forms_email simple_forms_form_number && Flipper.enabled?(:simple_forms_email_notifications) end From 3461d4c50103e9e4946dd1d10d8e3e8d2d02f069 Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Thu, 24 Oct 2024 12:58:41 -0400 Subject: [PATCH 56/58] Refactoring to less vars --- app/models/form_submission_attempt.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/models/form_submission_attempt.rb b/app/models/form_submission_attempt.rb index 17fd2e1358e..33a6fd1866a 100644 --- a/app/models/form_submission_attempt.rb +++ b/app/models/form_submission_attempt.rb @@ -25,13 +25,14 @@ class FormSubmissionAttempt < ApplicationRecord event :fail do after do - user_account_uuid = form_submission.user_account_id form_type = form_submission.form_type - log_info = { form_submission_id:, benefits_intake_uuid: form_submission&.benefits_intake_uuid, form_type:, - user_account_uuid: } + log_info = { form_submission_id:, + benefits_intake_uuid: form_submission&.benefits_intake_uuid, + form_type:, + user_account_uuid: form_submission.user_account_id } if should_send_simple_forms_email simple_forms_api_email(log_info) - elsif form_submission.form_type == CentralMail::SubmitForm4142Job::FORM4142_FORMSUBMISSION_TYPE + elsif form_type == CentralMail::SubmitForm4142Job::FORM4142_FORMSUBMISSION_TYPE form_526_form4142_email(log_info) end end From a1d470cc7a403f530a2c351e3755022594e62a41 Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Thu, 24 Oct 2024 14:04:08 -0400 Subject: [PATCH 57/58] Fixing test cases --- app/models/form_submission_attempt.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/form_submission_attempt.rb b/app/models/form_submission_attempt.rb index 33a6fd1866a..a16181e3284 100644 --- a/app/models/form_submission_attempt.rb +++ b/app/models/form_submission_attempt.rb @@ -33,7 +33,7 @@ class FormSubmissionAttempt < ApplicationRecord if should_send_simple_forms_email simple_forms_api_email(log_info) elsif form_type == CentralMail::SubmitForm4142Job::FORM4142_FORMSUBMISSION_TYPE - form_526_form4142_email(log_info) + form526_form4142_email(log_info) end end @@ -112,7 +112,7 @@ def form526_form4142_email(log_info) ) ZeroSilentFailures::Monitor.new(Form526Submission::ZSF_DD_TAG_SERVICE).log_silent_failure( log_info.merge({ error_class: e.class, error_message: e.message }), - user_account_uuid, call_location: + log_info[:user_account_uuid], call_location: ) end From 643e726745fb2562bd74065d282822bc69ff96c8 Mon Sep 17 00:00:00 2001 From: Kyle Soskin <37049625+kylesoskin@users.noreply.github.com> Date: Thu, 24 Oct 2024 14:52:58 -0400 Subject: [PATCH 58/58] Spelling mistake --- app/sidekiq/central_mail/submit_form4142_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/sidekiq/central_mail/submit_form4142_job.rb b/app/sidekiq/central_mail/submit_form4142_job.rb index b3cc46afad1..837d876f95f 100644 --- a/app/sidekiq/central_mail/submit_form4142_job.rb +++ b/app/sidekiq/central_mail/submit_form4142_job.rb @@ -150,7 +150,7 @@ def upload_to_lighthouse log_info = { benefits_intake_uuid: lighthouse_service.uuid, submission_id: @submission_id } Rails.logger.info( - 'Successful Form4142 Upload Intake UUID aquired from Lighthouse', + 'Successful Form4142 Upload Intake UUID acquired from Lighthouse', log_info )