[WHIT-3592] Enqueue role publishing jobs from after_commit#11565
Open
TonyGDS wants to merge 1 commit into
Open
[WHIT-3592] Enqueue role publishing jobs from after_commit#11565TonyGDS wants to merge 1 commit into
TonyGDS wants to merge 1 commit into
Conversation
The Ministers page Cabinet ministers section, and related published pages, are rebuilt from live role and appointment data whenever a role, role appointment, person or ministerial role changes. These republish jobs were enqueued from after_save/after_update/after_destroy callbacks that run inside the database transaction, so a Sidekiq worker could pick the job up before the transaction committed and republish pre-commit data, dropping the very change that triggered it. Move the callbacks to after_commit so the jobs are enqueued only once the change is durably committed and any worker is guaranteed to read it.
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.
What
Move the Publishing API republish callbacks on
Role,RoleAppointment,PersonandMinisterialRolefromafter_save/after_update/after_destroytoafter_commit.Why
A new cabinet minister appeared under Departmental ministers but not Cabinet ministers on the live Ministers page until an editor manually re-ordered the list.
The Cabinet ministers section is rebuilt from a single
PatchLinkSeton theministers_indexcontent item, derived from live appointment data. That patch was enqueued from anafter_savecallback, which runs inside the DB transaction. Publishing API event logs confirmed the appointment committed at20:06:52 UTCand thePatchLinkSetat that same second rebuilt the list of 21 ministers without the new appointment — the Sidekiq worker read the row before the transaction committed. Nothing re-patched until the manual re-order. The Departmental section was unaffected because it is rebuilt by a full Organisation republish triggered from several paths.Fix
Enqueue these jobs from
after_commitso they only run once the change is durably committed and any worker is guaranteed to read it. No change to the payloads sent; only the timing and the failure semantics (a failed enqueue no longer rolls back the editorial save — consistent withOrganisation's existingafter_save_commit).