fix(db): aggregate multi-service project policy batches in latestByPolicy (#730) - #731
Open
chbndrhnns wants to merge 1 commit into
Open
Conversation
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.
Fixes #730
Problem
When a backup policy targets an entire project (
serviceId === null), triggering the policy fans out and creates a batch of concurrentbackup_runrows (one for each enabled service in the project).However,
repos.backupRun.latestByPolicy(policyId)previously ran a singlefindFirstquery ordered bystartedAt DESC, returning only the single child run that happened to be inserted last (e.g.,122.0 KBfrom Redis in a multi-service project).This caused two issues in the Destination details page (
/backups/:id) and Jobs view (/jobs):122.0 KB), contradicting the Destination Total Stored rollup (29.8 MB).Solution
latestByPolicy: Inpackages/db/src/repos/backup.repo.ts,latestByPolicynow locates the newest run and finds all sibling runs for the policy within a 60-second window aroundstartedAt(the execution batch).bytesTransferred: Sums transferred bytes across runs in the batch.status: Resolves composite status (in-flight if any run is running;failedif any run failed/errored/cancelled;succeededif all succeeded).startedAt: EarlieststartedAtin the batch.finishedAt: LatestfinishedAtin the batch (ornullif any run is in-flight).packages/db/src/repos/backup-latest-by-policy.repo.test.tsverifying single-run policies, multi-service batch aggregation, failure status propagation, in-flight state handling, and batch isolation from historical runs.