Skip to content

Commit 434a315

Browse files
committed
Move already had notification sending to after commit
`ImmunisationImport` was triggering the `AlreadyHadNotificationSender` within the transaction that wraps the import process. This could theoretically lead to issues with the email job getting queued in Sidekiq before the data has been committed to the database. This is a possible reason for some of the missing emails that have been reported in prod and test. Jira-Issue: MAV-3418
1 parent 38b34df commit 434a315

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

app/models/immunisation_import.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,15 @@ def postprocess_rows!
217217

218218
PatientTeamUpdater.call(patient_scope: patients)
219219
PatientStatusUpdater.call(patient_scope: Patient.where(id: patients.ids))
220+
end
221+
222+
def post_commit!
223+
vaccination_records.sync_all_to_nhs_immunisations_api
220224

221225
vaccination_records
222226
.includes(:patient, :team, :subteam)
223227
.find_each do |vaccination_record|
224228
AlreadyHadNotificationSender.call(vaccination_record:)
225229
end
226230
end
227-
228-
def post_commit!
229-
vaccination_records.sync_all_to_nhs_immunisations_api
230-
end
231231
end

spec/models/immunisation_import_spec.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,14 @@
539539
SyncVaccinationRecordToNHSJob
540540
).with(vaccination_record.id).once.on("immunisations_api_sync")
541541
end
542+
543+
it "calls the AlreadyHadNotificationSender for the vaccination record" do
544+
expect(AlreadyHadNotificationSender).to receive(:call).with(
545+
vaccination_record:
546+
)
547+
548+
immunisation_import.send :post_commit!
549+
end
542550
end
543551

544552
describe "#postprocess_rows!" do
@@ -576,13 +584,5 @@
576584
).by(1)
577585
end
578586
end
579-
580-
it "calls the AlreadyHadNotificationSender for the vaccination record" do
581-
expect(AlreadyHadNotificationSender).to receive(:call).with(
582-
vaccination_record:
583-
)
584-
585-
immunisation_import.send :postprocess_rows!
586-
end
587587
end
588588
end

0 commit comments

Comments
 (0)