-
Notifications
You must be signed in to change notification settings - Fork 10.2k
feat: add cron job to cleanup old queued form responses #22035
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add cron job to cleanup old queued form responses #22035
Conversation
- Add cleanup cron job for App_RoutingForms_QueuedFormResponse table - Delete records with null actualResponseId older than 1 hour - Schedule to run twice daily (every 12 hours) via vercel.json - Follow existing cron job patterns for authentication and structure Co-Authored-By: hariom@cal.com <hariom@cal.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 2 Skipped Deployments
|
✅ No security or compliance issues detected. Reviewed everything up to 9927b29. Security Overview
Detected Code ChangesThe diff is too large to display a summary of code changes. Reply to this PR with |
- Change from lte to gte in createdAt comparison - Now properly deletes records older than 1 hour Co-Authored-By: hariom@cal.com <hariom@cal.com>
Closing due to inactivity for more than 7 days. Configure here. |
…ndpoint - Create cleanupExpiredQueuedFormResponses function in routing forms lib - Update API endpoint to import and use the new cleanup function - Follow established patterns for code organization in Cal.com - Maintain same functionality and authentication logic Co-Authored-By: hariom@cal.com <hariom@cal.com>
- Create routing-forms/cron/queuedFormResponseCleanup.ts with complete handler - Move authentication, HTTP handling, and database operations to routing-forms - Update API endpoint to simply import and call the cron handler - Remove old lib cleanup function - Follow user's preferred organizational pattern Co-Authored-By: hariom@cal.com <hariom@cal.com>
E2E results are ready! |
- Change from gte (greater than or equal) to lt (less than) cutoffTime - Now properly deletes records where createdAt < cutoffTime (older than 1 hour) - Previous logic was deleting newer records instead of older ones Co-Authored-By: hariom@cal.com <hariom@cal.com>
…nup-queued-form-responses
Important Review skippedBot user detected. To trigger a single review, invoke the You can disable this status message by setting the 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
- Move repository and service files to routingForm/queuedFormResponse subdirectory - Clean up unused methods and tests for better maintainability - Fix import paths and type definitions - Ensure all tests pass and maintain backward compatibility
- Update actualResponseId type from string to number to match Prisma Int type - Make updatedAt nullable (Date | null) to match Prisma DateTime? type - Fix import path for QueuedFormResponseRepository interface Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com>
@coderabbitai Review the PR |
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chainI'll review this PR for you. Let me start by gathering information about the changes and examining the code. 🏁 Script executed:
Length of output: 3283 Now let me examine the specific code changes to provide a thorough review: 🏁 Script executed:
Length of output: 776 Let me fix the command syntax to get the file contents: 🏁 Script executed:
Length of output: 764 Let me try a different approach to get the file contents: 🏁 Script executed:
Length of output: 18151 @hariombalhara Thank you for asking me to review this PR! I've analyzed the code changes and here's my comprehensive review: ✅ StrengthsArchitecture & Design:
Code Quality:
|
- Move repository and service files to routingForm/queuedFormResponse subdirectory - Clean up unused methods and tests for better maintainability - Fix import paths and type definitions - Ensure all tests pass and maintain backward compatibility
@coderabbitai recheck the duration issue has been fixed |
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed:
Length of output: 647 🏁 Script executed:
Length of output: 5769 @hariombalhara Perfect! ✅ I can confirm that the duration issue has been completely resolved. 🎯 Issue Resolution ConfirmedLooking at the current implementation in private getExpiryCutoffTime(): Date {
const olderThanDays = 7; // ✅ Now correctly uses 7 days (1 week)
return new Date(Date.now() - olderThanDays * 24 * 60 * 60 * 1000);
} What's been fixed:
📈 Updated AssessmentWith this critical issue resolved, my rating for this PR increases significantly: New Rating: 9/10 - Excellent implementation with proper architecture, comprehensive testing, and now consistent duration handling. The cron schedule of every 12 hours (in Great job on addressing the feedback! 🐰 |
Graphite Automations"Add consumer team as reviewer" took an action on this PR • (07/18/25)1 reviewer was added to this PR based on Keith Williams's automation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM just have one non-blocking comment
where: { | ||
actualResponseId: null, | ||
createdAt: { | ||
lt: cutoffTime, | ||
}, | ||
}, | ||
params: { | ||
take: batchSize, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels like this Prisma specific where statement should live inside the PrismaQueuedFormResponseRepository
. If it's outside of that repository then we're inherently creating a dependency on Prisma.
@emrysal what are your thoughts on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joeauyeung I didn't choose to do it because I am not sure if we have an example of an interface that is capable of defining complex AND or Logic.
So I though maybe we could use this prisma like interface itself as the generic interface. If you would notice we aren't importing Prisma in here https://github.com/calcom/cal.com/blob/devin/1750861124-cleanup-queued-form-responses/packages/lib/server/repository/routingForm/queuedFormResponse/QueuedFormResponseRepository.interface.ts#L0-L1
I will start a thread to discuss what approach should we take
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hariombalhara actually talking with @emrysal these type of comments should be blocking as we want to progress our code
.../server/repository/routingForm/queuedFormResponse/PrismaQueuedFormResponseRepository.test.ts
Outdated
Show resolved
Hide resolved
We are yet to finalize how to decouple prisma type from repository. I think for now having an interface that uses types similar to prisma but don't import prisma could work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👏
Add cron job to cleanup old queued form responses
Fixes:
PRI-289
Summary
This PR adds a cleanup cron job for the
App_RoutingForms_QueuedFormResponse
table to automatically delete old records that:actualResponseId
asnull
Changes Made
New cron job:
Created
/apps/web/app/api/cron/queuedFormResponseCleanup/route.ts
Deletion logic:
Deletes records where:
actualResponseId
isnull
, andcreatedAt
is older than 1 weekUpdated
vercel.json
:0 */12 * * *
(runs at midnight and noon)/api/cron/queuedFormResponseCleanup
Link to Devin Run
app.devin.ai/sessions/ae393cc887ed4532926a0bc1b0354dfa
Requested by: hariom@cal.com