-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Penison 91844 Failed Benefits Intake Remediation Reporting
- Loading branch information
1 parent
4d2ca74
commit 9850890
Showing
2 changed files
with
102 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'lighthouse/benefits_intake/service' | ||
|
||
class BenefitsIntakeRemediationJob | ||
include Sidekiq::Job | ||
|
||
sidekiq_options retry: false | ||
|
||
STATS_KEY = 'api.benefits_intake.remediation_status' | ||
BATCH_SIZE = Settings.lighthouse.benefits_intake.report.batch_size || 1000 | ||
|
||
attr_reader :batch_size | ||
|
||
def initialize(batch_size: BATCH_SIZE) | ||
@batch_size = batch_size | ||
end | ||
|
||
def perform | ||
Rails.logger.info('BenefitsIntakeRemediationJob started') | ||
|
||
|
||
start_dates = FormSubmission.group(:form_type).minimum(:created_at) | ||
failed = FormSubmission.joins(:form_submission_attempts).where(form_type: '21P-527EZ', form_submission_attempts: {aasm_state: 'failure'}) | ||
Check failure on line 24 in app/sidekiq/benefits_intake_remediation_job.rb GitHub Actions / Linting and Security
Check failure on line 24 in app/sidekiq/benefits_intake_remediation_job.rb GitHub Actions / Linting and Security
Check failure on line 24 in app/sidekiq/benefits_intake_remediation_job.rb GitHub Actions / Linting and Security
|
||
|
||
pending_form_submissions = FormSubmission | ||
.joins(:form_submission_attempts) | ||
.where(form_submission_attempts: { aasm_state: 'pending' }) | ||
total_handled, result = batch_process(pending_form_submissions) | ||
|
||
Rails.logger.info('BenefitsIntakeRemediationJob ended', total_handled:) if result | ||
end | ||
|
||
private | ||
|
||
def batch_process(pending_form_submissions) | ||
total_handled = 0 | ||
intake_service = BenefitsIntake::Service.new | ||
|
||
pending_form_submissions.each_slice(batch_size) do |batch| | ||
batch_uuids = batch.map(&:benefits_intake_uuid) | ||
response = intake_service.bulk_status(uuids: batch_uuids) | ||
raise response.body unless response.success? | ||
|
||
total_handled += handle_response(response, batch) | ||
end | ||
|
||
[total_handled, true] | ||
rescue => e | ||
Rails.logger.error('Error processing Intake Status batch', class: self.class.name, message: e.message) | ||
[total_handled, false] | ||
end | ||
|
||
# rubocop:disable Metrics/MethodLength | ||
def handle_response(response, pending_form_submissions) | ||
total_handled = 0 | ||
|
||
response.body['data']&.each do |submission| | ||
uuid = submission['id'] | ||
form_submission = pending_form_submissions.find do |submission_from_db| | ||
submission_from_db.benefits_intake_uuid == uuid | ||
end | ||
form_id = form_submission.form_type | ||
|
||
form_submission_attempt = form_submission.latest_pending_attempt | ||
|
||
# https://developer.va.gov/explore/api/benefits-intake/docs | ||
status = submission.dig('attributes', 'status') | ||
if %w[error expired].include?(status) | ||
# Error - Indicates that there was an error. Refer to the error code and detail for further information. | ||
# Expired - Indicate that documents were not successfully uploaded within the 15-minute window. | ||
form_submission_attempt.fail! | ||
log_result('failure', form_id, uuid, time_to_transition) | ||
elsif status == 'vbms' | ||
# submission was successfully uploaded into a Veteran's eFolder within VBMS | ||
form_submission_attempt.vbms! | ||
log_result('success', form_id, uuid, time_to_transition) | ||
elsif time_to_transition > STALE_SLA.days | ||
# exceeds SLA (service level agreement) days for submission completion | ||
log_result('stale', form_id, uuid, time_to_transition) | ||
else | ||
# no change being tracked | ||
log_result('pending', form_id, uuid) | ||
end | ||
|
||
total_handled += 1 | ||
end | ||
|
||
total_handled | ||
end | ||
# rubocop:enable Metrics/MethodLength | ||
|
||
def log_result(result, form_id, uuid, time_to_transition = nil) | ||
StatsD.increment("#{STATS_KEY}.#{form_id}.#{result}") | ||
StatsD.increment("#{STATS_KEY}.all_forms.#{result}") | ||
Rails.logger.info('BenefitsIntakeStatusJob', result:, form_id:, uuid:, time_to_transition:) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters