Skip to content

Add scheduled Firebase Cloud Function to delete old export status documents#131

Merged
kunalkeshan merged 7 commits intomainfrom
copilot/delete-old-export-docs
Dec 25, 2025
Merged

Add scheduled Firebase Cloud Function to delete old export status documents#131
kunalkeshan merged 7 commits intomainfrom
copilot/delete-old-export-docs

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 25, 2025

  • Understand the issue: Create a scheduled Firebase Cloud Function to delete export status documents older than 2 days
  • Explore the codebase and understand the export status document structure
  • Initialize Firebase Functions directory structure
    • Created functions/ directory with TypeScript configuration
    • Added functions/package.json with firebase-admin and firebase-functions dependencies
    • Added functions/tsconfig.json for TypeScript compilation
    • Added functions/.eslintrc.js for linting
  • Create the scheduled cloud function using Firebase Admin SDK
    • Function runs daily at midnight UTC using cron expression 0 0 * * *
    • Parses date from document IDs (format: "wed-dec-25-2024")
    • Deletes documents older than 2 days (configurable via constant)
    • Uses batch processing with Promise.allSettled for performance
    • Includes comprehensive logging
  • Configure Firebase project settings
    • Added firebase.json with functions configuration
    • Added .firebaserc linking to "mind-check-app" project
  • Run code review and security scan
    • Addressed code review feedback (extracted constant, added batch processing)
    • CodeQL scan passed with 0 alerts
  • Updated .gitignore for Firebase artifacts
  • Added documentation for future updates
    • Created functions/README.md with setup, development, deployment, and troubleshooting guides
    • Updated CONTRIBUTING.md with Firebase Cloud Functions section
  • Applied reviewer feedback:
    • Added paginated queries (100 users per batch) for scalability with large user bases
    • Changed schedule to cron expression 0 0 * * * for predictable midnight UTC execution
    • Improved error logging to include document context (userId, docId, docDate) when deletions fail
    • Fixed date parsing to use end of day (23:59:59.999) to ensure full retention period
    • Added error rate threshold (50%) to throw and alert monitoring systems for persistent issues
Original prompt

This section details on the original issue you should resolve

<issue_title>Delete Old Export Status Documents (Anything over 2 days old)</issue_title>
<issue_description></issue_description>

<agent_instructions>Read documentation here - https://console.firebase.google.com/u/2/project/mind-check-app/functions

pnpm install -g firebase-tools

$ firebase deploy

Not sure if I have to write the code here or in the firebase console, update as such and let me know, see if deploy firebase funcitons can be run during build time of the code at the same time?

Additional documdetaion, please read

https://firebase.google.com/docs/functions/get-started?authuser=2&_gl=1*1iteudr*_ga*MTU3MzExMTA5NS4xNzY2MzAwODk3*_ga_CW55HF8NVT*czE3NjY3MDMzMTYkbzQkZzEkdDE3NjY3MDM0MzIkajEwJGwwJGgw

https://github.com/firebase/functions-samples

Main things here - https://firebase.google.com/docs/functions/schedule-functions essentaially I want to schedule this delete old export status documents. </agent_instructions>

Comments on the Issue (you are @copilot in this section)

@kunalkeshan Use Firebase Admin SDK to create cloud function

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@vercel
Copy link
Copy Markdown

vercel bot commented Dec 25, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
mind-check Ready Ready Preview, Comment Dec 25, 2025 11:44pm

Co-authored-by: kunalkeshan <68579547+kunalkeshan@users.noreply.github.com>
Copilot AI changed the title [WIP] Delete export status documents older than two days Add scheduled Firebase Cloud Function to delete old export status documents Dec 25, 2025
Copilot AI requested a review from kunalkeshan December 25, 2025 23:06
@kunalkeshan kunalkeshan marked this pull request as ready for review December 25, 2025 23:13
@kunalkeshan
Copy link
Copy Markdown
Owner

@copilot check codebase and add relevant documentation for this for future updates.

Co-authored-by: kunalkeshan <68579547+kunalkeshan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Dec 25, 2025

@copilot check codebase and add relevant documentation for this for future updates.

Added documentation in commit 6e60991:

  • Created functions/README.md with comprehensive documentation covering setup, development, deployment, monitoring, and troubleshooting
  • Updated CONTRIBUTING.md with a new Firebase Cloud Functions section

The documentation includes guides for adding new functions, useful commands, and links to Firebase references.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a scheduled Firebase Cloud Function that automatically deletes export status documents older than 2 days from Firestore. The implementation includes comprehensive logging, batch processing for performance, and proper error handling.

Key changes:

  • Scheduled function running every 24 hours to clean up old export status documents
  • Date parsing from document IDs in format "day-mon-dd-yyyy"
  • Batch processing with configurable concurrency (10 concurrent deletes)

Reviewed changes

Copilot reviewed 9 out of 12 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
functions/src/index.ts Core Cloud Function implementation with date parsing and batch deletion logic
functions/package.json Dependencies and npm scripts for Firebase Functions
functions/tsconfig.json TypeScript compiler configuration for ES2017 target
functions/.eslintrc.js ESLint configuration with TypeScript plugin
functions/.gitignore Ignores compiled lib directory and debug logs
functions/README.md Comprehensive documentation for development and deployment
firebase.json Firebase project configuration with predeploy hooks
.firebaserc Links to "mind-check-app" Firebase project
.gitignore Excludes Firebase artifacts and functions/lib directory
CONTRIBUTING.md Updated with Firebase Cloud Functions setup instructions

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread functions/src/index.ts Outdated
Comment thread functions/src/index.ts Outdated
Comment thread functions/src/index.ts Outdated
Comment thread functions/src/index.ts Outdated
Comment thread functions/src/index.ts Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: kunalkeshan <68579547+kunalkeshan@users.noreply.github.com>
@kunalkeshan kunalkeshan merged commit 89c409a into main Dec 25, 2025
3 checks passed
@kunalkeshan kunalkeshan deleted the copilot/delete-old-export-docs branch December 25, 2025 23:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Delete Old Export Status Documents (Anything over 2 days old)

3 participants