Skip to content

Commit

Permalink
add hca_zero_silent_failures flipper toggle and use it for metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
coope93 committed Dec 19, 2024
1 parent 2492450 commit 36dc2d2
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 17 deletions.
14 changes: 7 additions & 7 deletions app/models/health_care_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def log_sync_submission_failure
end

def log_async_submission_failure
log_zero_silent_failures
log_zero_silent_failures unless Flipper.enabled?(:hca_zero_silent_failures)
StatsD.increment("#{HCA::Service::STATSD_KEY_PREFIX}.failed_wont_retry")
StatsD.increment("#{HCA::Service::STATSD_KEY_PREFIX}.failed_wont_retry_short_form") if short_form?
log_submission_failure_details
Expand Down Expand Up @@ -295,19 +295,19 @@ def send_failure_email
api_key = Settings.vanotify.services.health_apps_1010.api_key

salutation = first_name ? "Dear #{first_name}," : ''
VANotify::EmailJob.perform_async(
email,
template_id,
{ 'salutation' => salutation },
api_key,
metadata =
{
callback_metadata: {
notification_type: 'error',
form_number: FORM_ID,
statsd_tags: DD_ZSF_TAGS
}
}
)

params = [email, template_id, { 'salutation' => salutation }, api_key]
params << metadata if Flipper.enabled?(:hca_zero_silent_failures)

VANotify::EmailJob.perform_async(*params)
StatsD.increment("#{HCA::Service::STATSD_KEY_PREFIX}.submission_failure_email_sent")
rescue => e
log_exception_to_sentry(e)
Expand Down
3 changes: 3 additions & 0 deletions config/features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ features:
hca_retrieve_facilities_without_repopulating:
actor_type: user
description: Constrain facilities endpoint to only return existing facilities values - even if the table is empty, do not rerun the Job to populate it.
hca_zero_silent_failures:
actor_type: user
description: Pass callback metadata to vanotify sidekiq job
cg1010_oauth_2_enabled:
actor_type: user
description: Use OAuth 2.0 Authentication for 10-10CG Form Mulesoft integration.
Expand Down
51 changes: 41 additions & 10 deletions spec/models/health_care_application_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ def self.expect_job_submission(job)

before do
allow(VANotify::EmailJob).to receive(:perform_async)
allow(Flipper).to receive(:enabled?).with(:hca_zero_silent_failures).and_return(false)
end

describe '#send_failure_email' do
Expand All @@ -560,18 +561,32 @@ def self.expect_job_submission(job)
{
'salutation' => "Dear #{health_care_application.parsed_form['veteranFullName']['first']},"
},
api_key,
{
api_key
]
end

let(:standard_error) { StandardError.new('Test error') }

context ':hca_zero_silent_failures enabled' do
before do
allow(Flipper).to receive(:enabled?).with(:hca_zero_silent_failures).and_return(true)
end

let(:template_params_with_callback_metadata) do
template_params << {
callback_metadata: {
notification_type: 'error',
form_number: form_id,
statsd_tags: zsf_tags
}
}
]
end
end

let(:standard_error) { StandardError.new('Test error') }
it 'sends a failure email to the email address provided on the form with callback metadata' do
subject
expect(VANotify::EmailJob).to have_received(:perform_async).with(*template_params_with_callback_metadata)
end
end

it 'sends a failure email to the email address provided on the form' do
subject
Expand Down Expand Up @@ -601,19 +616,35 @@ def self.expect_job_submission(job)
{
'salutation' => ''
},
api_key,
{
api_key
]
end

let(:standard_error) { StandardError.new('Test error') }

context ':hca_zero_silent_failures enabled' do
before do
allow(Flipper).to receive(:enabled?).with(:hca_zero_silent_failures).and_return(true)
end

let(:template_params_no_name_with_callback_metadata) do
template_params_no_name << {
callback_metadata: {
notification_type: 'error',
form_number: form_id,
statsd_tags: zsf_tags
}
}
]
end

it 'sends a failure email to the email address provided on the form with callback metadata' do
subject
expect(VANotify::EmailJob).to have_received(:perform_async).with(
*template_params_no_name_with_callback_metadata
)
end
end

let(:standard_error) { StandardError.new('Test error') }

it 'sends a failure email without personalisations to the email address provided on the form' do
subject
expect(VANotify::EmailJob).to have_received(:perform_async).with(*template_params_no_name)
Expand Down

0 comments on commit 36dc2d2

Please sign in to comment.