fix: phase 2 hardening - added meta collection to store last updated …#12
Merged
sujallchaudhary merged 1 commit intoJun 27, 2026
Merged
Conversation
…time for each platform
|
@Devx2107 is attempting to deploy a commit to the my-projects Team on Vercel. A member of the Team first needs to authorize 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.
fix: hardening — cron health visibility, admin rate limiting, CodeChef fallback
What
Three reliability improvements: surface cron health on
/api/health, rate-limit the admin update endpoint, and stop zeroing out CodeChef stats on a transient scrape failure.Why
This project runs on a single self-hosted machine. There's currently no way to tell if the daily cron actually ran, the admin update endpoint can be spammed with no limit, and a temporary CodeChef scrape failure wipes a student's stats to zero instead of just keeping the last known good data.
Changes
New file —
backend/models/Meta.jsMinimal key-value collection (
key,value,updatedAt) for system metadata that doesn't belong on the Student or Snapshot schemas. Used here forlastCronRun, but generic enough to reuse later.backend/cron/updateData.jsupdateAllStudents(), upserts{ key: 'lastCronRun', value: new Date() }into theMetacollectionfetchStatsreturnsnull(non-404 failure, i.e. likely a transient scrape break), the existing stats are now preserved instead of being left at their schema default. A newcodechef.lastFetchFailedboolean is set totrueso the failure is visible without losing data. On a successful fetch, the flag is reset tofalse.backend/platforms/codechef.jsNo functional change —
fetchStatsalready correctly returnsnullon failure. The handling of thatnullmoved to the cron layer since that's where the existing stats live.backend/models/Student.jscodechef.lastFetchFailed: { type: Boolean, default: false }backend/app.jsGET /api/healthnow also returnslastCronRun(read from theMetacollection) alongside the existingstatusandtimestampNew file —
backend/middlewares/adminLimiter.jsStrict rate limiter using
express-rate-limit(already a dependency): 3 requests per 15 minutes, scoped only to/api/admin. Kept separate from any general API rate limiting so student-facing routes are unaffected.backend/routes/admin.jsadminLimiterto the/updaterouteTesting
node backend/scripts/runUpdate.js— confirmedMetacollection gets alastCronRunentry and/api/healthreflects itlastFetchFailedflips totrue; reverted and confirmed a successful run resets it tofalse/api/admin/update4 times within 15 minutes — 4th request correctly returns 429Notes
lastCronRunis intentionally minimal — no per-platform breakdown in this PR, just a single "did the cron run today" signal. Frontend can build a "last updated" badge off this without further backend work.lastFetchFailedis added only for CodeChef in this PR since it's the only scraped (vs. API-based) platform and therefore the most failure-prone. Can be extended to other platforms in a follow-up if needed.