Skip to content

Commit

Permalink
Merge branch 'master' into dbex/94144_trigger_email_on_polled_4142_fa…
Browse files Browse the repository at this point in the history
…ilure
  • Loading branch information
kylesoskin committed Oct 25, 2024
2 parents 244f851 + a90afb5 commit 6ffb51c
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ GEM
google-protobuf (4.28.3)
bigdecimal
rake (>= 13)
googleauth (1.11.1)
googleauth (1.11.2)
faraday (>= 1.0, < 3.a)
google-cloud-env (~> 2.1)
jwt (>= 1.4, < 3.0)
Expand Down Expand Up @@ -748,7 +748,7 @@ GEM
hashery (~> 2.0)
ruby-rc4
ttfunk
pg (1.5.8)
pg (1.5.9)
pg_query (5.1.0)
google-protobuf (>= 3.22.3)
pg_search (2.3.7)
Expand Down
1 change: 1 addition & 0 deletions app/models/appeal_submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class AppealSubmission < ApplicationRecord
has_encrypted :upload_metadata, key: :kms_key, **lockbox_options

has_many :appeal_submission_uploads, dependent: :destroy
has_many :secondary_appeal_forms, dependent: :destroy

scope :failure_not_sent, -> { where(failure_notification_sent_at: nil).order(id: :asc) }

Expand Down
4 changes: 4 additions & 0 deletions config/features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1618,6 +1618,10 @@ features:
actor_type: user
description: HLR show form content updates
enable_in_development: true
sc_new_form:
actor_type: user
description: Supplemental Claim new form updates
enable_in_development: true
pension_ipf_callbacks_endpoint:
actor_type: user
description: Pension IPF VANotify notification callbacks endpoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def self.call(*)

# @param lighthouse526_document_uploads [Lighthouse526DocumentUpload] a collection of
# Lighthouse526DocumentUpload records polled for status updates on Lighthouse's '/uploads/status' endpoint
# @param lighthouse_status_response [Hash] the parsed JSON response body from the endpoint
def initialize(lighthouse526_document_uploads, lighthouse_status_response)
@lighthouse526_document_uploads = lighthouse526_document_uploads
@lighthouse_status_response = lighthouse_status_response
Expand Down Expand Up @@ -66,34 +67,29 @@ def update_document_status(status)
document_upload = @lighthouse526_document_uploads.find_by!(lighthouse_document_request_id: status['requestId'])
statsd_document_base_key(STATSD_DOCUMENT_TYPE_KEY_MAP[document_upload.document_type])

status_updater(status, document_upload)
@status_updater.update_status
status_updater = BenefitsDocuments::Form526::UploadStatusUpdater.new(status, document_upload)
status_updater.update_status

if document_upload.completed?
# ex. 'api.form526.lighthouse_document_upload_processing_status.bdd_instructions.complete'
StatsD.increment("#{@statsd_document_base_key}.#{STATSD_DOCUMENT_COMPLETE_KEY}")
elsif document_upload.failed?
log_failure(document_upload)
elsif @status_updater.processing_timeout?
log_failure(status_updater, document_upload)
elsif status_updater.processing_timeout?
# Triggered when a document is still pending more than 24 hours after processing began
# ex. 'api.form526.lighthouse_document_upload_processing_status.bdd_instructions.processing_timeout'
StatsD.increment("#{@statsd_document_base_key}.#{STATSD_PROCESSING_TIMEOUT_KEY}")
end
end

def status_updater(status, document_upload)
# UploadStatusUpdater encapsulates all parsing of a status response from Lighthouse
@status_updater ||= BenefitsDocuments::Form526::UploadStatusUpdater.new(status, document_upload)
end

def statsd_document_base_key(statsd_document_type_key)
@statsd_document_base_key ||= "#{STATSD_BASE_KEY}.#{statsd_document_type_key}"
end

def log_failure(document_upload)
def log_failure(status_updater, document_upload)
# Because Lighthouse's processing steps are subject to change, these metrics must be dynamic.
# Currently, this should return either CLAIMS_EVIDENCE or BENEFITS_GATEWAY_SERVICE
failure_step = @status_updater.get_failure_step
failure_step = status_updater.get_failure_step

# ex. 'api.form526.lighthouse_document_upload_processing_status.bdd_instructions.failed.claims_evidence'
StatsD.increment("#{@statsd_document_base_key}.#{STATSD_DOCUMENT_FAILED_KEY}.#{failure_step.downcase}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,49 @@
end
end
end

context 'when updating multiple records' do
let!(:first_pending_polling_document) { create(:lighthouse526_document_upload, aasm_state: 'pending') }
let!(:second_pending_polling_document) { create(:lighthouse526_document_upload, aasm_state: 'pending') }

let(:status_response) do
{
'data' => {
'statuses' => [
{
'requestId' => first_pending_polling_document.lighthouse_document_request_id,
'time' => {
'startTime' => start_time_in_unix_milliseconds,
'endTime' => end_time_in_unix_milliseconds
},
'status' => 'SUCCESS'
}, {
'requestId' => second_pending_polling_document.lighthouse_document_request_id,
'time' => {
'startTime' => start_time_in_unix_milliseconds,
'endTime' => end_time_in_unix_milliseconds
},
'status' => 'FAILED',
'error' => {
'detail' => 'Something went wrong',
'step' => 'BENEFITS_GATEWAY_SERVICE'
}
}
],
'requestIdsNotFound' => [
0
]
}
}
end

it 'updates each record status properly' do
described_class.call(Lighthouse526DocumentUpload.all, status_response)

expect(first_pending_polling_document.reload.aasm_state).to eq('completed')
expect(second_pending_polling_document.reload.aasm_state).to eq('failed')
end
end
end

describe 'document type in statsd metrics' do
Expand Down
2 changes: 1 addition & 1 deletion spec/models/accredited_organization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

RSpec.describe AccreditedOrganization, type: :model do
describe 'validations' do
subject { build(:accredited_organization) }
subject { build(:accredited_organization, poa_code: 'A12') }

it { is_expected.to have_many(:accredited_individuals).through(:accreditations) }

Expand Down

0 comments on commit 6ffb51c

Please sign in to comment.