[FIX] base_bg: commit before NOTIFY to avoid 10-min job delay#408
Closed
cos-adhoc wants to merge 1 commit into
Closed
[FIX] base_bg: commit before NOTIFY to avoid 10-min job delay#408cos-adhoc wants to merge 1 commit into
cos-adhoc wants to merge 1 commit into
Conversation
Contributor
e9e7389 to
a21f549
Compare
There was a problem hiding this comment.
Pull request overview
Este PR busca evitar una condición de carrera al encolar trabajos en base_bg: el runner de crons puede despertarse antes de que los bg.job sean visibles en BD, provocando demoras de ~10 minutos hasta el siguiente tick.
Changes:
- Se agrega un
commit()antes de llamar a_trigger_crons()al finalizarbg_enqueue_records(). - Se ajustan tests existentes para mockear
cr.commit()y evitar commits reales duranteTransactionCase. - Se agregan tests que validan el orden
commit → triggery que el commit ocurra una sola vez por lote.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| base_bg/models/base_bg.py | Inserta cr.commit() antes de disparar crons al finalizar el encolado. |
| base_bg/tests/test_bg_job.py | Actualiza mocks por el nuevo commit y agrega tests de orden/contaje del commit. |
a21f549 to
3af1abe
Compare
3af1abe to
6966c02
Compare
6966c02 to
706886e
Compare
Contributor
|
@roboadhoc r+ nobump |
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.

bg_enqueue_records sent the PostgreSQL NOTIFY via _trigger_crons() before the transaction was committed. The cron runner woke up, found no enqueued jobs (not yet visible), and went back to sleep until the next scheduled tick (~10 min). Adding cr.commit() after all batch jobs are created guarantees visibility before the NOTIFY is sent.