[Card Locking] Add engineering alert mailer for lock/unlock events - #14512
Open
garyhtou wants to merge 1 commit into
Open
[Card Locking] Add engineering alert mailer for lock/unlock events#14512garyhtou wants to merge 1 commit into
garyhtou wants to merge 1 commit into
Conversation
Alerts HCB engineers via a Slack-posting email address whenever any user's cards get locked or unlocked, to verify the recently-shipped card-locking feature behaves correctly in production. Hooks in at the User model level (an after_update_commit callback keyed on cards_locked changing) rather than in UserService::UpdateCardLocking, so it catches every writer of that column, not just the one service. Counts and suppression state are captured at the moment of the transition and passed into the mailer, rather than queried live inside the async delivery job, so the alert describes the transition it's reporting on rather than whatever state exists whenever the job happens to run. When an unlock leaves overdue charges outstanding and isn't from admin suppression (a supported action that unlocks without resolving receipts by design), it's reported via Rails.error.unexpected as a violated precondition. Recipient is env-var-driven via Credentials.fetch(:SLACK_HCB_ENGR_ALERTS_EMAIL). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of the problem
Card locking shipped ~2 weeks ago. To verify it's behaving correctly in production, HCB engineers want an alert whenever any user's cards get locked or unlocked.
Describe your changes
EngineeringAlertMailerwithcards_locked/cards_unlockedactions, sent to a Slack-posting address viaCredentials.fetch(:SLACK_HCB_ENGR_ALERTS_EMAIL)(unset today; add the real value in Doppler separately). Content is intentionally minimal (name, email, admin link, counts — no merchant/amount detail).Usermodelafter_update_commitcallback (CardLocking::CardholderBehavior, keyed onsaved_change_to_cards_locked?) rather than insideUserService::UpdateCardLocking, so it fires on any writer ofcards_locked, not just that one service.Rails.error.unexpectedas a violated precondition — reported to AppSignal in production, raised loudly in development/test.Note for reviewers: there's no
Rails.env.production?gate on delivery — the only thing preventing this from firing outside production isSLACK_HCB_ENGR_ALERTS_EMAILstaying unset there. That mirrors howAdminMailer/OrganizerPositionDeletionRequestMaileralready handleSLACK_NOTIFICATIONS_EMAILin this codebase, but worth confirming the Doppler value doesn't get shared into a staging config before this ships.