feat: implement background cleanup job for ephemeral messages with configurable TTL and audit logging#175
Open
pixels26 wants to merge 1 commit into
Open
Conversation
…nfigurable TTL and audit logging
|
@pixels26 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! 🚀 |
Collaborator
|
@pixels26 please fix build |
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.
Close #112
Background Cleanup Job for Ephemeral Messages
Description
Implement a background process to automatically delete ephemeral messages after a configurable time-to-live (TTL). This ensures privacy and reduces unnecessary storage usage in AnonChat.
Type of Change
Changes Made
Database
is_ephemeralandexpires_atcolumns to messages tableephemeral_message_configtable for per-room TTL settingsglobal_ephemeral_configtable for system-wide defaultsephemeral_message_cleanup_logstable for audit trailBackend Services
lib/ephemeral-cleanup.ts): Main cleanup logic with batch processing, error handling, and cache invalidationlib/ephemeral-config.ts): Types, constants, and configuration valuesPOST/GET /api/ephemeral/config- Manage TTL settings per room or globallyPOST/GET /api/ephemeral/cleanup- Trigger cleanup and retrieve statisticsGET /api/ephemeral/cron- Vercel cron integrationapp/api/messages/route.ts): Support for creating ephemeral messagesScheduling
vercel.json): Automatic cleanup every 6 hours in productionscripts/ephemeral-cleanup-worker.js): Configurable background worker for self-hosted deploymentsscripts/trigger-cleanup.mjs): On-demand cleanup for testingTesting & Documentation
scripts/test-ephemeral-cleanup.mjs)EPHEMERAL_MESSAGES_README.md)EPHEMERAL_SETUP.md)EPHEMERAL_TESTING_GUIDE.md)EPHEMERAL_TESTING_STEPS.md)Acceptance Criteria Met
Technical Implementation
Key Features
Configuration Options
API Usage
Create Ephemeral Message
POST /api/messages { "room_id": "room_123", "content": "Ephemeral message", "is_ephemeral": true }Configure TTL
POST /api/ephemeral/config { "room_id": "room_123", "ttl_seconds": 3600, "enabled": true }Get Statistics
Testing
Comprehensive testing guide included in EPHEMERAL_TESTING_STEPS.md with 10 phases:
Estimated testing time: 30-45 minutes
Deployment
Production (Vercel)
VERCEL_CRON_SECRETenvironment variablegit push- cron automatically scheduledSelf-Hosted (Docker)
Breaking Changes
None. This is a non-breaking feature addition.
Dependencies Added
node-cron(^3.0.3) - For scheduling background jobsFiles Added/Modified
New Files:
Modified Files:
Security Considerations
Performance Impact
Related Issues
Closes #[issue-number] (if applicable)
Checklist
Screenshots/Examples
Cleanup Statistics
{ "stats": { "totalEphemeralMessages": 1500, "expiredMessages": 50, "deletedToday": 120, "deletedThisMonth": 2500 } }Audit Log Entry
{ "id": "log-uuid", "deleted_message_id": "msg-uuid", "room_id": "room_123", "deleted_at": "2024-06-01T14:30:00Z", "reason": "expired" }Additional Notes