Skip to content

Commit

Permalink
Merge branch 'master' into arf.92364/clarify-gclaws-vets-api-next-steps
Browse files Browse the repository at this point in the history
* master:
  case9 logic fixed (#18362)
  API-39748-add-index-to-error-collection-messages (#18333)
  Use random value in Simple Forms PDF stamping file paths (#18361)
  Add `find_dependents_by_ptcpnt_id` to local bgs (#18303)
  remove request_ping defs (#18353)
  API-38827-update-validations-intl-postal-code (#18323)
  [Document Upload Failure] Email veteran on Form 0781/Form 0781a upload retry exhaustion (#18206)
  add feature flags for meb and 5490 (#18328)
  Handle 500 responses from VA Profile v3 Service for v0/profile/contacts endpoint (#18192)
  Resolve MethodLength Rubocop Disables - Part 3 (#18331)
  Resolve MethodLength Rubocop Disables - Part BGS::Form674 (#18326)
  • Loading branch information
gabezurita committed Sep 9, 2024
2 parents eb932ad + a1d4863 commit fdd811e
Show file tree
Hide file tree
Showing 31 changed files with 673 additions and 254 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# frozen_string_literal: true

require 'va_notify/service'

module EVSS
module DisabilityCompensationForm
class Form0781DocumentUploadFailureEmail < Job
STATSD_METRIC_PREFIX = 'api.form_526.veteran_notifications.form0781_upload_failure_email'

# retry for one day
sidekiq_options retry: 14

sidekiq_retries_exhausted do |msg, _ex|
job_id = msg['jid']
error_class = msg['error_class']
error_message = msg['error_message']
timestamp = Time.now.utc
form526_submission_id = msg['args'].first

# Job status records are upserted in the JobTracker module
# when the retryable_error_handler is called
form_job_status = Form526JobStatus.find_by(job_id:)
bgjob_errors = form_job_status.bgjob_errors || {}
new_error = {
"#{timestamp.to_i}": {
caller_method: __method__.to_s,
timestamp:,
form526_submission_id:
}
}
form_job_status.update(
status: Form526JobStatus::STATUS[:exhausted],
bgjob_errors: bgjob_errors.merge(new_error)
)

Rails.logger.warn(
'Form0781DocumentUploadFailureEmail 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 Form0781DocumentUploadFailureEmail#sidekiq_retries_exhausted',
{
job_id:,
messaged_content: e.message,
submission_id: form526_submission_id,
pre_exhaustion_failure: {
error_class:,
error_message:
}
}
)
raise e
end

def perform(form526_submission_id)
form526_submission = Form526Submission.find(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

notify_client.send_email(
email_address:,
template_id: mailer_template_id,
personalisation: {
first_name:,
date_submitted:
}
)

StatsD.increment("#{STATSD_METRIC_PREFIX}.success")
end
rescue => e
retryable_error_handler(e)
end

private

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
super(error)
raise error
end

def mailer_template_id
Settings.vanotify.services
.benefits_disability.template_id.form0781_upload_failure_notification_template_id
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ class SubmitForm0781 < Job

StatsD.increment("#{STATSD_KEY_PREFIX}.exhausted")

if Flipper.enabled?(:form526_send_0781_failure_notification)
EVSS::DisabilityCompensationForm::Form0781DocumentUploadFailureEmail.perform_async(form526_submission_id)
end

::Rails.logger.warn(
'Submit Form 0781 Retries exhausted',
{ job_id:, error_class:, error_message:, timestamp:, form526_submission_id: }
Expand Down
52 changes: 26 additions & 26 deletions app/sidekiq/lighthouse/submit_benefits_intake_claim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class BenefitsIntakeClaimError < StandardError; end
StatsD.increment("#{STATSD_KEY_PREFIX}.exhausted")
end

# rubocop:disable Metrics/MethodLength
def perform(saved_claim_id)
@claim = SavedClaim.find(saved_claim_id)

Expand All @@ -39,20 +38,11 @@ def perform(saved_claim_id)
else
process_record(@claim)
end
@attachment_paths = @claim.persistent_attachments.map do |record|
process_record(record)
end
@attachment_paths = @claim.persistent_attachments.map { |record| process_record(record) }

create_form_submission_attempt

payload = {
upload_url: @lighthouse_service.location,
file: split_file_and_path(@pdf_path),
metadata: generate_metadata.to_json,
attachments: @attachment_paths.map(&method(:split_file_and_path))
}

response = @lighthouse_service.upload_doc(**payload)
response = @lighthouse_service.upload_doc(**lighthouse_service_upload_payload)
raise BenefitsIntakeClaimError, response.body unless response.success?

Rails.logger.info('Lighthouse::SubmitBenefitsIntakeClaim succeeded', generate_log_details)
Expand All @@ -65,7 +55,6 @@ def perform(saved_claim_id)
cleanup_file_paths
end

# rubocop:enable Metrics/MethodLength
def generate_metadata
form = @claim.parsed_form
veteran_full_name = form['veteranFullName']
Expand All @@ -84,7 +73,6 @@ def generate_metadata
SimpleFormsApiSubmission::MetadataValidator.validate(metadata, zip_code_is_us_based: check_zipcode(address))
end

# rubocop:disable Metrics/MethodLength
def process_record(record, timestamp = nil, form_id = nil)
pdf_path = record.to_pdf
stamped_path1 = PDFUtilities::DatestampPdf.new(pdf_path).run(text: 'VA.GOV', x: 5, y: 5, timestamp:)
Expand All @@ -95,29 +83,41 @@ def process_record(record, timestamp = nil, form_id = nil)
text_only: true
)
if form_id.present? && ['21P-530V2'].include?(form_id)
PDFUtilities::DatestampPdf.new(stamped_path2).run(
text: 'Application Submitted on va.gov',
x: 425,
y: 675,
text_only: true, # passing as text only because we override how the date is stamped in this instance
timestamp:,
page_number: 5,
size: 9,
template: "lib/pdf_fill/forms/pdfs/#{form_id}.pdf",
multistamp: true
)
stamped_pdf_with_form(form_id, stamped_path2, timestamp)
else
stamped_path2
end
end

# rubocop:enable Metrics/MethodLength
def split_file_and_path(path)
{ file: path, file_name: path.split('/').last }
end

private

def lighthouse_service_upload_payload
{
upload_url: @lighthouse_service.location,
file: split_file_and_path(@pdf_path),
metadata: generate_metadata.to_json,
attachments: @attachment_paths.map(&method(:split_file_and_path))
}
end

def stamped_pdf_with_form(form_id, path, timestamp)
PDFUtilities::DatestampPdf.new(path).run(
text: 'Application Submitted on va.gov',
x: 425,
y: 675,
text_only: true, # passing as text only because we override how the date is stamped in this instance
timestamp:,
page_number: 5,
size: 9,
template: "lib/pdf_fill/forms/pdfs/#{form_id}.pdf",
multistamp: true
)
end

def generate_log_details(e = nil)
details = {
claim_id: @claim.id,
Expand Down
11 changes: 11 additions & 0 deletions config/features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,10 @@ features:
actor_type: user
description: Enables enqueuing a Form4142DocumentUploadFailureEmail if a SubmitForm4142Job job exhausts its retries
enable_in_development: true
form526_send_0781_failure_notification:
actor_type: user
description: Enables enqueuing a Form0781DocumentUploadFailureEmail if a SubmitForm0781Job job exhausts its retries
enable_in_development: true
form0994_confirmation_email:
actor_type: user
description: Enables form 0994 email submission confirmation (VaNotify)
Expand Down Expand Up @@ -1173,6 +1177,13 @@ features:
show_meb_service_history_categorize_disagreement:
actor_type: user
enable_in_development: false
show_meb_5490_maintenance_alert:
actor_type: user
description: Displays an alert to users on 5490 intro page that the Backend Service is Down.
enable_in_development: false
meb_1606_30_automation:
actor_type: user
description: Enables MEB form to handle Chapter 1606/30 forms as well as Chapter 33.
meb_exclusion_period_enabled:
actor_type: user
description: enables exclusion period checks
Expand Down
1 change: 1 addition & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1356,6 +1356,7 @@ vanotify:
template_id:
form526_document_upload_failure_notification_template_id: form526_document_upload_failure_notification_template_id
form4142_upload_failure_notification_template_id: form4142_upload_failure_notification_template_id
form0781_upload_failure_notification_template_id: form0781_upload_failure_notification_template_id
ivc_champva:
api_key: fake_secret
template_id:
Expand Down
48 changes: 26 additions & 22 deletions lib/bgs/form674.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,17 @@ module BGS
class Form674
include SentryLogging

attr_reader :user, :saved_claim
attr_reader :user, :saved_claim, :proc_id

def initialize(user, saved_claim)
@user = user
@proc_id = vnp_proc_id
@saved_claim = saved_claim
@end_product_name = '130 - Automated School Attendance 674'
@end_product_code = '130SCHATTEBN'
end

# rubocop:disable Metrics/MethodLength
def submit(payload)
proc_id = create_proc_id_and_form
veteran = VnpVeteran.new(proc_id:, payload:, user:, claim_type: '130SCHATTEBN').create

process_relationships(proc_id, veteran, payload)
Expand All @@ -38,16 +37,7 @@ def submit(payload)
# temporary logging to troubleshoot
log_message_to_sentry("#{proc_id} - #{@end_product_code}", :warn, '', { team: 'vfs-ebenefits' })

benefit_claim_record = BenefitClaim.new(
args: {
vnp_benefit_claim: vnp_benefit_claim_record,
veteran:,
user:,
proc_id:,
end_product_name: @end_product_name,
end_product_code: @end_product_code
}
).create
benefit_claim_record = BenefitClaim.new(args: benefit_claim_args(vnp_benefit_claim_record, veteran)).create

begin
vnp_benefit_claim.update(benefit_claim_record, vnp_benefit_claim_record)
Expand All @@ -60,19 +50,23 @@ def submit(payload)

bgs_service.update_proc(proc_id, proc_state: 'MANUAL_VAGOV')
rescue
Rails.logger.warning('BGS::Form674.submit failed after creating benefit claim in BGS',
{
user_uuid: user.uuid,
saved_claim_id: saved_claim.id,
icn: user.icn,
error: e.message
})
log_submit_failure(error)
end
end
# rubocop:enable Metrics/MethodLength

private

def benefit_claim_args(vnp_benefit_claim_record, veteran)
{
vnp_benefit_claim: vnp_benefit_claim_record,
veteran:,
user:,
proc_id:,
end_product_name: @end_product_name,
end_product_code: @end_product_code
}
end

def process_relationships(proc_id, veteran, payload)
dependent = DependentHigherEdAttendance.new(proc_id:, payload:, user: @user).create

Expand All @@ -96,7 +90,7 @@ def process_674(proc_id, dependent, payload)
).create
end

def create_proc_id_and_form
def vnp_proc_id
vnp_response = bgs_service.create_proc(proc_state: 'MANUAL_VAGOV')
bgs_service.create_proc_form(
vnp_response[:vnp_proc_id],
Expand Down Expand Up @@ -130,6 +124,16 @@ def set_claim_type(proc_state)
end
end

def log_submit_failure(error)
Rails.logger.warning('BGS::Form674.submit failed after creating benefit claim in BGS',
{
user_uuid: user.uuid,
saved_claim_id: saved_claim.id,
icn: user.icn,
error: error.message
})
end

def bgs_service
BGS::Service.new(@user)
end
Expand Down
30 changes: 16 additions & 14 deletions lib/bgs/marriages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def create_all

private

# rubocop:disable Metrics/MethodLength
def report_marriage_history(type)
@dependents_application[type].each do |former_spouse|
former_marriage = BGSDependents::MarriageHistory.new(former_spouse)
Expand All @@ -35,22 +34,25 @@ def report_marriage_history(type)
participant,
'Spouse',
'Ex-Spouse',
{
type:,
begin_date: marriage_info['start_date'],
marriage_country: marriage_info['marriage_country'],
marriage_state: marriage_info['marriage_state'],
marriage_city: marriage_info['marriage_city'],
divorce_state: marriage_info['divorce_state'],
divorce_city: marriage_info['divorce_city'],
divorce_country: marriage_info['divorce_country'],
end_date: marriage_info['end_date'],
marriage_termination_type_code: marriage_info['marriage_termination_type_code']
}
spouse_dependent_optional_fields(type, marriage_info)
)
end
end
# rubocop:enable Metrics/MethodLength

def spouse_dependent_optional_fields(type, marriage_info)
{
type:,
begin_date: marriage_info['start_date'],
marriage_country: marriage_info['marriage_country'],
marriage_state: marriage_info['marriage_state'],
marriage_city: marriage_info['marriage_city'],
divorce_state: marriage_info['divorce_state'],
divorce_city: marriage_info['divorce_city'],
divorce_country: marriage_info['divorce_country'],
end_date: marriage_info['end_date'],
marriage_termination_type_code: marriage_info['marriage_termination_type_code']
}
end

def add_spouse
spouse = BGSDependents::Spouse.new(@dependents_application)
Expand Down
Loading

0 comments on commit fdd811e

Please sign in to comment.