Overview
The TWIGZ backend uses Convex cron jobs to automate recurring maintenance tasks. These jobs run on fixed schedules and call internal functions to handle cleanup and data hygiene operations. Location:convex/crons.ts
All cron jobs call internal functions that are not directly accessible from client applications. They run automatically on the Convex server and require no manual intervention.
Scheduled Jobs
Cleanup Abandoned Carts
Schedule: Daily at 2:00 AM UTC (
0 2 * * *)
Internal Function: internal.customers.cartUtils.cleanupAbandonedCarts
Parameter: daysOld: 30Removes shopping carts that have been inactive for more than 30 days. This prevents stale cart data from accumulating in the database and ensures storage remains efficient.Cleanup Invalid Carts
Schedule: Weekly on Sunday at 3:00 AM UTC (
0 3 * * 0)
Internal Function: internal.customers.cartUtils.cleanupInvalidCarts
Parameters: NoneIdentifies and removes carts that are in an invalid state, such as carts referencing deleted products or stores that no longer exist.Cleanup Stale Device Tokens
Schedule: Weekly on Monday at 4:00 AM UTC (
0 4 * * 1)
Internal Function: internal.shared.notifications.cleanupStaleDeviceTokens
Parameter: daysInactive: 90Deactivates push notification device tokens (FCM/APNS) that have not been updated in over 90 days. This reduces failed notification delivery attempts and keeps the token registry clean.Schedule Summary
| Job | Schedule | Frequency | Purpose |
|---|---|---|---|
| Cleanup Abandoned Carts | 0 2 * * * | Daily at 2 AM | Remove carts older than 30 days |
| Cleanup Invalid Carts | 0 3 * * 0 | Weekly (Sunday 3 AM) | Remove carts with invalid references |
| Cleanup Stale Device Tokens | 0 4 * * 1 | Weekly (Monday 4 AM) | Deactivate tokens inactive 90+ days |
How It Works
Convex Cron Engine
Convex evaluates cron expressions and triggers the associated internal function at the specified time.
Internal Function Execution
The target internal function runs within a Convex mutation or action context, querying and modifying the database as needed.
Related Functions
- Cart Utilities — Customer cart management and the underlying cleanup logic
- Notifications — Push notification system including device token management
