-
Notifications
You must be signed in to change notification settings - Fork 0
fix(scheduler): status guards + RETURNING + single backoff source (Sourcery on #69) #70
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (complexity): Envisagez de simplifier la nouvelle logique de backoff et de retry en parsant les timestamps plus tôt, en renforçant les invariants, et en simplifiant le flux de données et les tests, tout en gardant Rust comme unique source de vérité.
Vous pouvez conserver l’objectif « Rust comme unique source de vérité » tout en réduisant sensiblement la complexité de la nouvelle logique de backoff et du flux de données.
1. Parser
last_attempt_atune seule fois dansrow_to_post_recordAu lieu de parser le RFC3339 à chaque appel de
backoff_window_elapsed, parsez-le au moment de la construction et stockez une valeur typée (ouOption) dansPostRecord. Cela supprime le bruit lié au parsing et à la politique d’erreur dans le prédicat de backoff.Avec cela,
backoff_window_elapsedpeut se concentrer uniquement sur la logique de fenêtre temporelle :2. Renforcer les invariants de backoff et l’indexation
Étant donné l’invariant selon lequel la table couvre toutes les tentatives, vous pouvez simplifier l’indexation défensive en remplaçant la gymnastique
.get().unwrap_or_else(..)par un simpleclamp:Ensuite, le
clampci-dessus suffit ; vous n’avez plus besoin des fallbacks.get()plus.last().3. Éviter le
Vec<PostRecord>intermédiaire danslist_due_for_publishVous pouvez conserver le backoff côté Rust tout en évitant la passe supplémentaire collect/filter en filtrant lors du mapping :
Cela maintient toute la logique en Rust (pas de
CASESQL) tout en réduisant le pipeline de transformation à une boucle simple.4. Petit helper de test pour réduire la répétition
Les nouveaux tests offrent une bonne couverture d’état mais dupliquent un peu de SQL « lecture status/failed_attempts ». Un petit helper leur permet de se concentrer sur les transitions :
Ensuite, des tests comme
mark_failed_skips_when_status_is_not_publishingdeviennent un peu plus faciles à lire :Tout ce qui précède conserve les nouveaux comportements (backoff piloté par Rust, garde-fous, résultats) tout en rendant le flux de contrôle et la politique de backoff plus faciles à comprendre.
Original comment in English
issue (complexity): Consider simplifying the new backoff and retry logic by parsing timestamps earlier, tightening invariants, and streamlining data flow and tests while keeping Rust as the single source of truth.
You can keep the “single source of truth in Rust” goal while trimming a fair bit of complexity from the new backoff logic and data flow.
1. Parse
last_attempt_atonce inrow_to_post_recordInstead of parsing RFC3339 in every
backoff_window_elapsedcall, parse at construction time and store a typed value (orOption) inPostRecord. That removes parsing and error-policy noise from the backoff predicate.With that,
backoff_window_elapsedcan focus purely on the time-window logic:2. Tighten the backoff invariants and indexing
Given the invariant that the table covers all attempts, you can simplify the defensive indexing, replacing the
.get().unwrap_or_else(..)dance with a simple clamp:Then the
clampabove is enough; you no longer need.get()plus.last()fallbacks.3. Avoid the intermediate
Vec<PostRecord>inlist_due_for_publishYou can keep the Rust-side backoff while avoiding the extra collect/filter pass by filtering during mapping:
This keeps all logic in Rust (no SQL
CASE) but reduces the transformation pipeline to a straightforward loop.4. Small test helper to reduce repetition
The new tests add good state coverage but duplicate a bit of “read status/failed_attempts” SQL. A tiny helper keeps them focused on transitions:
Then tests like
mark_failed_skips_when_status_is_not_publishingbecome a little easier to scan:All of the above keeps the new behaviors (Rust-driven backoff, guards, outcomes) intact while making the control flow and backoff policy easier to reason about.