Skip to content

101987 Removed champva_multiple_stamp_retry feature toggle and improved handle_upload - IVC CHAMPVA forms #20642

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions config/features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,6 @@ features:
champva_log_all_s3_uploads:
actor_type: user
description: Enables logging for all s3 uploads using UUID or keys for monitoring
champva_multiple_stamp_retry:
actor_type: user
description: Enables retry of file creation for some errors in CHAMPVA PDF stamping
champva_failure_email_job_enabled:
actor_type: user
description: Enables sending failure notification emails for IVC CHAMPVA form submissions that lack a Pega status
Expand Down
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated handle_file_uploads method to remove the champva_multiple_stamp_retry toggle check and the associated extra branch of functionality.

Original file line number Diff line number Diff line change
Expand Up @@ -89,48 +89,31 @@ def submit_supporting_documents
#
# @return [Array<Integer, String>] An array with 1 or more http status codes
# and an array with 1 or more message strings.
def handle_file_uploads(form_id, parsed_form_data) # rubocop:disable Metrics/MethodLength
if Flipper.enabled?(:champva_multiple_stamp_retry, @current_user)
attempt = 0
max_attempts = 1

begin
file_paths, metadata = get_file_paths_and_metadata(parsed_form_data)
hu_result = FileUploader.new(form_id, metadata, file_paths, true).handle_uploads
# convert [[200, nil], [400, 'error']] -> [200, 400] and [nil, 'error'] arrays
statuses, error_messages = hu_result[0].is_a?(Array) ? hu_result.transpose : hu_result.map { |i| Array(i) }

# Since some or all of the files failed to upload to S3, trigger retry
raise StandardError, error_messages if error_messages.compact.length.positive?
rescue => e
attempt += 1
error_message_downcase = e.message.downcase
Rails.logger.error "Error handling file uploads (attempt #{attempt}): #{e.message}"

if should_retry?(error_message_downcase, attempt, max_attempts)
Rails.logger.error 'Retrying in 1 seconds...'
sleep 1
retry
end
end
else
def handle_file_uploads(form_id, parsed_form_data)
attempt = 0
max_attempts = 1

begin
file_paths, metadata = get_file_paths_and_metadata(parsed_form_data)
hu_result = FileUploader.new(form_id, metadata, file_paths, true).handle_uploads
# convert [[200, nil], [400, 'error']] -> [200, 400] and [nil, 'error'] arrays
statuses, error_messages = hu_result[0].is_a?(Array) ? hu_result.transpose : hu_result.map { |i| Array(i) }

# Retry attempt if specific error message is found
if error_messages.any? do |message|
message.is_a?(String) && message.include?('No such file or directory @ rb_sysopen')
end
file_paths, metadata = get_file_paths_and_metadata(parsed_form_data)
hu_result = FileUploader.new(form_id, metadata, file_paths, true).handle_uploads
statuses, error_messages = hu_result[0].is_a?(Array) ? hu_result.transpose : hu_result.map { |i| Array(i) }
# Since some or all of the files failed to upload to S3, trigger retry
raise StandardError, error_messages if error_messages.compact.length.positive?
rescue => e
attempt += 1
error_message_downcase = e.message.downcase
Rails.logger.error "Error handling file uploads (attempt #{attempt}): #{e.message}"

if should_retry?(error_message_downcase, attempt, max_attempts)
Rails.logger.error 'Retrying in 1 seconds...'
sleep 1
retry
end
end

[statuses, error_messages]
end # rubocop:enable Metrics/MethodLength
end

def should_retry?(error_message_downcase, attempt, max_attempts)
error_conditions = [
Expand Down
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjusted tests so there are no longer references to the feature toggle that was removed.

Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@
before do
# TODO: add tests to cover when the `require_all_s3_success` feature is enabled
allow(Flipper).to receive(:enabled?).with(:champva_require_all_s3_success, @current_user).and_return(false)
allow(Flipper).to receive(:enabled?).with(:champva_multiple_stamp_retry, @current_user).and_return(true)
allow(controller).to receive(:get_file_paths_and_metadata).and_return([file_paths, metadata])
allow(IvcChampva::FileUploader).to receive(:new).and_return(file_uploader)
end
Expand Down Expand Up @@ -337,7 +336,6 @@
let(:expected_error_message) { [nil, 'Upload failed'] } # All error message strings

before do
# allow(Flipper).to receive(:enabled?).with(:champva_multiple_stamp_retry, @current_user).and_return(true)
allow(file_uploader).to receive(:handle_uploads).and_return(error_response)
end

Expand All @@ -346,7 +344,7 @@
end
end

context 'when champva_multiple_stamp_retry is enabled and a file repeatedly fails to load' do
context 'when a file repeatedly fails to load' do
before do
allow(file_uploader).to receive(:handle_uploads).and_raise(StandardError.new('Unable to find file'))
# TODO: add tests to cover all other error conditions with handle_uploads, eg:
Expand Down
Loading