Skip to main content

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

JobScheduleFrequencyPurpose
Cleanup Abandoned Carts0 2 * * *Daily at 2 AMRemove carts older than 30 days
Cleanup Invalid Carts0 3 * * 0Weekly (Sunday 3 AM)Remove carts with invalid references
Cleanup Stale Device Tokens0 4 * * 1Weekly (Monday 4 AM)Deactivate tokens inactive 90+ days

How It Works

1

Convex Cron Engine

Convex evaluates cron expressions and triggers the associated internal function at the specified time.
2

Internal Function Execution

The target internal function runs within a Convex mutation or action context, querying and modifying the database as needed.
3

Automatic Retries

Convex handles retries for transient failures. If a cron job fails, it will be retried according to Convex’s built-in retry policy.
  • Cart Utilities — Customer cart management and the underlying cleanup logic
  • Notifications — Push notification system including device token management
Cron job execution logs are available in the Convex dashboard under the Functions tab. Filter by the internal function name to see execution history and any errors.