feat: add cron cleanup job for expired shares, trashed snippets, stale logs, and backup files - #165
Merged
SudiptaPaul-31 merged 2 commits intoAug 30, 2026
Conversation
…e logs, and backup files - Add CleanupService and CleanupRepository with batched deletes - Add /api/cron/cleanup route with Bearer auth - Schedule cleanup daily at 03:17 via vercel.json cron - Lazy-init DB clients in activity-logger and reputation to avoid crashes when DATABASE_URL is missing - Fix duplicate ResourceType export in activity-logger - Add eslint-disable for intentional control-char regex - Fix frontend-signature test env to jsdom - Update jest config: node env, TextDecoder polyfill in setup - Add missing test mocks for ipfs service and snippet update flow - Add undici and testing-library dev dependencies
|
@JemimahEkong is attempting to deploy a commit to the Sudipta 's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@JemimahEkong 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! 🚀 |
Owner
|
@JemimahEkong resolve conflicts |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Deployment failed for project v0-code-snippets-platform-24 with the following error: |
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.
feat: scheduled cleanup system for expired data and stale records
What
Introduces a scheduled cleanup system that runs daily at 03:17 UTC via Vercel Cron. It purges expired share links, soft-deleted snippets past retention, stale activity/analytics/audit logs, expired auth sessions, and old encrypted backup files.
Why
Without automated cleanup, expired shares, trashed snippets, and logs accumulate indefinitely — growing the database, leaking stale data past grace periods, and accumulating backup files on disk.
Changes
Core feature
app/api/cron/cleanup/route.ts— GET endpoint protected byCRON_SECRETBearer authlib/cleanup.service.ts— Orchestrates 5 independent tasks, continues on individual failures, returns a structured summary with per-task counts, durations, and errorslib/cleanup.repository.ts— Batched DELETE queries (500 rows/batch, max 20 batches) forsnippet_shares,snippets,auth_sessions,login_nonces,activity_logs,snippet_analytics, andauditslib/cleanup.service.test.ts— Tests covering service logic, config parsing, backup file pruning, error resilience, and batch behaviorvercel.json— Scheduled cron routeRetention defaults (configurable via env vars)
CLEANUP_SHARE_GRACE_DAYSTRASH_RETENTION_DAYSBACKUP_RETENTION_DAYSLOG_RETENTION_DAYSFixes and improvements
lib/activity-logger.ts— Lazy-init DB client to prevent crash whenDATABASE_URLis unset; remove duplicateResourceTypeexportlib/reputation.ts— Lazy-init DB client instead of failing at module loadlib/utils.ts— Addeslint-disablefor intentional control-char regexapp/api/snippets/[id]/transfer-ownership/route.ts—consttoletfor reassignable variableTest infrastructure
node(Node 22 has nativefetch), addjest.setup.jsforTextDecoder/TextEncoderpolyfilllib/snippet.service.test.ts: correct IPFSService mock path, add missingfindByIdmock for update-not-found case@jest-environment jsdompragma tovalidiation/frontend-signature.test.tsxDesign notes
CRON_SECRETBearer auth so it can't be triggered by unauthenticated requests.Testing
lib/cleanup.service.test.tscovers service orchestration logic, config parsing (env var overrides + defaults), backup file pruning, error resilience when an individual task fails, and batch-size/batch-count behavior.Acceptance criteria
Related
Closes #131