Skip to content

Commit

Permalink
App changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tfink419 committed Mar 26, 2024
1 parent e329262 commit a8b1cb6
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 26 deletions.
2 changes: 1 addition & 1 deletion app/controllers/v0/dependents_applications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def create
dependent_service.submit_686c_form(claim)

Rails.logger.info "ClaimID=#{claim.confirmation_number} Form=#{claim.class::FORM}"
clear_saved_form(claim.form_id)
# clear_saved_form(claim.form_id) # We do not want to destroy the InProgressForm for this submission

render(json: claim)
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/v0/in_progress_forms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class InProgressFormsController < ApplicationController
def index
# :unaltered prevents the keys from being deeply transformed, which might corrupt some keys
# see https://github.com/department-of-veterans-affairs/va.gov-team/issues/17595 for more details
render json: InProgressForm.for_user(@current_user), key_transform: :unaltered
render json: InProgressForm.submission_pending.for_user(@current_user), key_transform: :unaltered
end

def show
Expand Down Expand Up @@ -37,7 +37,7 @@ def destroy
private

def form_for_user
@form_for_user ||= InProgressForm.form_for_user(form_id, @current_user)
@form_for_user ||= InProgressForm.submission_pending.form_for_user(form_id, @current_user)
end

def form_id
Expand Down
2 changes: 2 additions & 0 deletions app/models/in_progress_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def cast(value)
scope :for_form, ->(form_id) { where(form_id:) }
scope :not_submitted, -> { where.not("metadata -> 'submission' ->> 'status' = ?", 'applicationSubmitted') }
scope :unsubmitted_fsr, -> { for_form('5655').not_submitted }
enum :status, %w[pending processing], prefix: :submission, default: :pending
scope :submission_pending, -> { where(status: [nil, 'pending']) } # override to include nil
attribute :user_uuid, CleanUUID.new
serialize :form_data, coder: JsonMarshal::Marshaller
has_kms_key
Expand Down
2 changes: 2 additions & 0 deletions app/services/bgs/dependent_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def get_dependents
def submit_686c_form(claim)
Rails.logger.info('BGS::DependentService running!', { user_uuid: uuid, saved_claim_id: claim.id, icn: })

InProgressForm.find_by(form_id: BGS::SubmitForm686cJob::FORM_ID, user_uuid: uuid)&.submission_processing!

encrypted_vet_info = KmsEncrypted::Box.new.encrypt(get_form_hash_686c.to_json)
submit_pdf_job(claim:, encrypted_vet_info:)

Expand Down
2 changes: 1 addition & 1 deletion app/services/users/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def veteran_status
end

def in_progress_forms
InProgressForm.for_user(user).map do |form|
InProgressForm.submission_pending.for_user(user).map do |form|
{
form: form.form_id,
metadata: form.metadata,
Expand Down
22 changes: 11 additions & 11 deletions app/sidekiq/bgs/submit_form674_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Invalid674Claim < StandardError; end
include Sidekiq::Job
include SentryLogging

attr_reader :claim, :user, :in_progress_copy, :user_uuid, :saved_claim_id, :vet_info, :icn
attr_reader :claim, :user, :user_uuid, :saved_claim_id, :vet_info, :icn

sidekiq_options retry: 14

Expand All @@ -19,23 +19,19 @@ class Invalid674Claim < StandardError; end
Rails.logger.error('BGS::SubmitForm674Job failed, retries exhausted...',
{ user_uuid:, saved_claim_id:, icn:, error: })

BGS::SubmitForm674Job.send_backup_submission(encrypted_user_struct_hash, vet_info, saved_claim_id)
BGS::SubmitForm674Job.send_backup_submission(encrypted_user_struct_hash, vet_info, saved_claim_id, user_uuid)
end

def perform(user_uuid, icn, saved_claim_id, encrypted_vet_info, encrypted_user_struct_hash = nil)
Rails.logger.info('BGS::SubmitForm674Job running!', { user_uuid:, saved_claim_id:, icn: })
instance_params(encrypted_vet_info, icn, encrypted_user_struct_hash, user_uuid, saved_claim_id)

in_progress_form = InProgressForm.find_by(form_id: FORM_ID, user_uuid:)
@in_progress_copy = in_progress_form_copy(in_progress_form)

submit_form

send_confirmation_email
in_progress_form&.destroy
Rails.logger.info('BGS::SubmitForm674Job succeeded!', { user_uuid:, saved_claim_id:, icn: })
InProgressForm.destroy_by(form_id: FORM_ID, user_uuid:)
rescue => e
salvage_save_in_progress_form(FORM_ID, user_uuid, @in_progress_copy) if @in_progress_copy.present?
handle_filtered_errors!(e:, encrypted_user_struct_hash:, encrypted_vet_info:)

Rails.logger.warn('BGS::SubmitForm674Job received error, retrying...',
Expand All @@ -52,7 +48,7 @@ def handle_filtered_errors!(e:, encrypted_user_struct_hash:, encrypted_vet_info:
{ user_uuid:, saved_claim_id:, icn:, error: e.message, nested_error: e.cause&.message })

vet_info = JSON.parse(KmsEncrypted::Box.new.decrypt(encrypted_vet_info))
self.class.send_backup_submission(encrypted_user_struct_hash, vet_info, saved_claim_id)
self.class.send_backup_submission(encrypted_user_struct_hash, vet_info, saved_claim_id, user_uuid)
raise Sidekiq::JobRetry::Skip
end

Expand All @@ -62,6 +58,7 @@ def instance_params(encrypted_vet_info, icn, encrypted_user_struct_hash, user_uu
@icn = icn
@user_uuid = user_uuid
@saved_claim_id = saved_claim_id
@claim = SavedClaim::DependencyClaim.find(saved_claim_id)
end

def self.generate_user_struct(encrypted_user_struct, vet_info)
Expand All @@ -85,7 +82,7 @@ def self.generate_user_struct(encrypted_user_struct, vet_info)
)
end

def self.send_backup_submission(encrypted_user_struct_hash, vet_info, saved_claim_id)
def self.send_backup_submission(encrypted_user_struct_hash, vet_info, saved_claim_id, user_uuid)
if Flipper.enabled?(:dependents_central_submission)
user = generate_user_struct(encrypted_user_struct_hash, vet_info)
CentralMail::SubmitCentralForm686cJob.perform_async(saved_claim_id,
Expand All @@ -94,13 +91,16 @@ def self.send_backup_submission(encrypted_user_struct_hash, vet_info, saved_clai
else
DependentsApplicationFailureMailer.build(user).deliver_now if user&.email.present? # rubocop:disable Style/IfInsideElse # Temporary for flipper
end
InProgressForm.destroy_by(form_id: FORM_ID, user_uuid:)
rescue => e
Rails.logger.warn('BGS::SubmitForm674Job backup submission failed...',
{ user_uuid:, saved_claim_id:, error: e.message, nested_error: e.cause&.message })
InProgressForm.find_by(form_id: FORM_ID, user_uuid:)&.submission_pending!
end

private

def submit_form
@claim = SavedClaim::DependencyClaim.find(saved_claim_id)

claim.add_veteran_info(vet_info)

raise Invalid674Claim unless claim.valid?(:run_686_form_jobs)
Expand Down
22 changes: 11 additions & 11 deletions app/sidekiq/bgs/submit_form686c_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Invalid686cClaim < StandardError; end
include Sidekiq::Job
include SentryLogging

attr_reader :claim, :user, :in_progress_copy, :user_uuid, :saved_claim_id, :vet_info, :icn
attr_reader :claim, :user, :user_uuid, :saved_claim_id, :vet_info, :icn

sidekiq_options retry: 14

Expand All @@ -19,23 +19,19 @@ class Invalid686cClaim < StandardError; end
Rails.logger.error('BGS::SubmitForm686cJob failed, retries exhausted!',
{ user_uuid:, saved_claim_id:, icn:, error: })

BGS::SubmitForm686cJob.send_backup_submission(vet_info, saved_claim_id)
BGS::SubmitForm686cJob.send_backup_submission(vet_info, saved_claim_id, user_uuid)
end

def perform(user_uuid, icn, saved_claim_id, encrypted_vet_info)
Rails.logger.info('BGS::SubmitForm686cJob running!', { user_uuid:, saved_claim_id:, icn: })
instance_params(encrypted_vet_info, icn, user_uuid, saved_claim_id)

in_progress_form = InProgressForm.find_by(form_id: FORM_ID, user_uuid:)
@in_progress_copy = in_progress_form_copy(in_progress_form)

submit_forms(encrypted_vet_info)

send_confirmation_email
in_progress_form&.destroy
Rails.logger.info('BGS::SubmitForm686cJob succeeded!', { user_uuid:, saved_claim_id:, icn: })
InProgressForm.destroy_by(form_id: FORM_ID, user_uuid:) unless claim.submittable_674?
rescue => e
salvage_save_in_progress_form(FORM_ID, user_uuid, @in_progress_copy) if @in_progress_copy.present?
handle_filtered_errors!(e:, encrypted_vet_info:)

Rails.logger.warn('BGS::SubmitForm686cJob received error, retrying...',
Expand All @@ -52,7 +48,7 @@ def handle_filtered_errors!(e:, encrypted_vet_info:)
{ user_uuid:, saved_claim_id:, icn:, error: e.message, nested_error: e.cause&.message })

vet_info = JSON.parse(KmsEncrypted::Box.new.decrypt(encrypted_vet_info))
self.class.send_backup_submission(vet_info, saved_claim_id)
self.class.send_backup_submission(vet_info, saved_claim_id, user_uuid)
raise Sidekiq::JobRetry::Skip
end

Expand All @@ -62,6 +58,7 @@ def instance_params(encrypted_vet_info, icn, user_uuid, saved_claim_id)
@icn = icn
@user_uuid = user_uuid
@saved_claim_id = saved_claim_id
@claim = SavedClaim::DependencyClaim.find(saved_claim_id)
end

def self.generate_user_struct(vet_info)
Expand All @@ -81,7 +78,7 @@ def self.generate_user_struct(vet_info)
)
end

def self.send_backup_submission(vet_info, saved_claim_id)
def self.send_backup_submission(vet_info, saved_claim_id, user_uuid)
if Flipper.enabled?(:dependents_central_submission)
user = generate_user_struct(vet_info)
CentralMail::SubmitCentralForm686cJob.perform_async(saved_claim_id,
Expand All @@ -90,13 +87,16 @@ def self.send_backup_submission(vet_info, saved_claim_id)
else
DependentsApplicationFailureMailer.build(user).deliver_now if user&.email.present? # rubocop:disable Style/IfInsideElse
end
InProgressForm.destroy_by(form_id: FORM_ID, user_uuid:)
rescue => e
Rails.logger.warn('BGS::SubmitForm686cJob backup submission failed...',
{ user_uuid:, saved_claim_id:, error: e.message, nested_error: e.cause&.message })
InProgressForm.find_by(form_id: FORM_ID, user_uuid:)&.submission_pending!
end

private

def submit_forms(encrypted_vet_info)
@claim = SavedClaim::DependencyClaim.find(saved_claim_id)

claim.add_veteran_info(vet_info)

raise Invalid686cClaim unless claim.valid?(:run_686_form_jobs)
Expand Down

0 comments on commit a8b1cb6

Please sign in to comment.