feat(jobs): wire leaderboard snapshotting into a scheduled queue (#991) - #1147
Merged
Akanimoh12 merged 1 commit intoJul 30, 2026
Conversation
Adds a leaderboard-snapshot BullMQ queue/worker that runs the existing createLeaderboardSnapshot() for every period (WEEKLY, MONTHLY, ALL_TIME) on a daily cron (LEADERBOARD_SNAPSHOT_CRON, defaults to 00:15 UTC). Idempotent: each period's snapshot is fully replaced (delete + recreate in one transaction) by createLeaderboardSnapshot, so re-running the job for the same window always converges to the same stored ranking. One period failing never blocks the others. Closes Akanimoh12#991
|
@DSOTec Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Akanimoh12
merged commit Jul 30, 2026
92d7891
into
Akanimoh12:test-implement-drips
4 of 5 checks passed
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.
Problem
createLeaderboardSnapshot(period, now)already exists inmodules/leaderboard/leaderboard.service.ts— it rebuildsLeaderboardSnapshotrows for a period (WEEKLY/MONTHLY/ALL_TIME) and is already idempotent (delete + recreate inside one transaction). Nothing scheduled it though: no queue, no worker, no cron entry, so snapshots were never actually produced.Solution
Wires it into the existing BullMQ job pattern used by
analyticsDaily/creditRecompute/subscriptionCharge:src/jobs/leaderboardSnapshot.queue.ts— singleton queue viagetQueue().src/jobs/leaderboardSnapshot.worker.ts:runLeaderboardSnapshot()callscreateLeaderboardSnapshotfor all three periods, isolating failures per period ({ processed, failed }, same shape asprocessDueSubscriptions) so one bad period never blocks the others.createLeaderboardSnapshotWorker()/scheduleLeaderboardSnapshot()register the BullMQ worker and a repeatable cron job.LEADERBOARD_SNAPSHOT_CRONenv var (default15 0 * * *, daily) added toenv.ts,.env.example, andconfig/index.ts.jobs/index.ts(exports) andjobs/main.ts(bootstrap + graceful shutdown), matching the other three jobs exactly.main.test.ts's config mock and assertions for the 4th scheduled job / closable worker.Idempotency: satisfied at the data layer —
createLeaderboardSnapshotfully replaces a period's rows (delete +createMany) inside a single transaction, so re-running the job for the same period always converges to the same stored ranking regardless of how many times it fires.Testing
npx eslinton all touched files — clean (only the sameno-explicit-anywarning every other worker already has forredis as any).npm run typecheck— no new errors (this branch already has 4 pre-existing errors from an unrelated parsing issue innotifications.test.ts, untouched here).npx vitest run src/jobs— 23/23 pass (19 existing + 4 new), including a dedicated idempotency test (running the job twice in a row produces identical output).npm run test(full suite) — 508 passed vs. 504 on the unmodified branch (+4 mine), same pre-existing DB-dependent failures, no regressions.Closes #991