Skip to content
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

Update callbacks to have _commit suffix #158

Merged
merged 2 commits into from
Aug 1, 2024
Merged

Conversation

ericaporter
Copy link
Contributor

@ericaporter ericaporter commented Jul 29, 2024

ECF reported that they were seeing a disparity between production db numbers and BigQuery arising during a transaction - the event is sending straight away so if the transaction ends up rolling back the analytics event has already been sent to BQ and doesn’t match the db

This PR updates the callbacks (after_create after_update and after_destroy) to be after_create_commit after_update_commit and after_destroy_commit so that events will only send after the transaction is complete but also if it rolls back the event will not send

ECF did some testing of this update:

The issue was initially detected in the method save_and_dedupe_participant https://github.com/DFE-Digital/early-careers-framework/blob/main/app/models/npq_application.rb#L134. I've tested the fix locally by using some binding.pry statements to highlight where the analytics log events are occurring and if it's where we expect.
Pic 1: Before the change. Here we can see the event is logged before the transaction is complete. We've hit the pry while still in the transaction but the event has already been sent.
Pic 2: Now with the gem update. We hit the first pry we had before inside the transaction without logging an analytics event and we then publish the event before hitting the second pry outside the transaction. This is what we want. After the first, before the second.
Pic 3: Also with the gem update. I raised a rollback error inside the transaction and we completed the transaction without sending any event whatsoever which again is what we want.
Screenshot 2024-07-29 at 16 52 30
Screenshot 2024-07-29 at 16 45 14
Screenshot 2024-07-29 at 16 32 46

@ericaporter ericaporter self-assigned this Jul 29, 2024
@ericaporter ericaporter requested a review from asatwal July 30, 2024 08:18
Copy link
Collaborator

@asatwal asatwal left a comment

Choose a reason for hiding this comment

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

👍 Nice work - LGTM.

@ericaporter ericaporter merged commit 682a223 into main Aug 1, 2024
7 checks passed
@ericaporter ericaporter deleted the update-callbacks branch August 1, 2024 10:37
@ericaporter ericaporter mentioned this pull request Aug 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants