Cron Jobs
Cron Job Summary
The scheduled jobs within the application are managed by sidekiq-scheduler and can be categorized into several functional groups. These jobs run at varying intervals to ensure data consistency, handle notifications, and perform regular system maintenance.
Running scheduled tasks (cron jobs) via Sidekiq offers the advantage of using the same server and environment as regular asynchronous jobs, which is particularly beneficial in a containerized setup like ours. This approach leverages the sidekiq-scheduler gem, providing a flexible syntax for defining job frequencies. However, this method has a critical operational constraint: to prevent jobs from being queued multiple times for the same scheduled instance, it is imperative that only one Sidekiq process is running the scheduler at any given time.
Our scheduled jobs enable a powerful pattern of performing operations in batches, which allows for faster data reads through denormalization and create a self-healing system where data inconsistencies from missed events are automatically corrected over time.
High-Frequency Jobs (Multiple times per hour)
A significant number of jobs run every few minutes to handle near real-time data processing and synchronization. These tasks are critical for the application's core operations and responsiveness.
- Order and Fulfillment: Core commerce functions are managed by frequently running jobs. For example,
Order::ExpirationJobandOrder::PendingNotificationJobrun every 5 minutes to manage the order lifecycle.Order::FareAutoAcceptJobalso runs every 5 minutes to process new fares automatically. - Data Synchronization: To maintain data integrity across the platform, numerous "Sync" jobs execute at a high frequency.
LiveModifierSyncandSyncMenuCategoriesJobrun every minute to keep menu data up-to-date. Other critical syncs, likeEnqueueDietarySyncsandSyncMenuItemVariantsJob, run every 3 minutes. - Polling and User Engagement: The polling feature is supported by several high-frequency jobs.
NotifyNewPollsJobandSendPollExpirationRemindersJobrun every 10 minutes to keep users engaged, whileAutoSubmitPollsJobruns every 15 minutes (*/15 * * * *). - Entity Management: Various jobs for managing core data models run frequently. For instance,
ClearOldCombosJobandCoupon::ExpirationJobrun every 5 minutes to handle data cleanup and status updates.
Medium-Frequency Jobs (Hourly)
Several essential processes are scheduled on an hourly or multi-hour basis. These jobs handle tasks that are important but less time-sensitive than the high-frequency jobs.
- Metrics and Reporting: To ensure data accuracy for analytics,
Order::MetricsJobruns every hour to aggregate and refresh order data. Similarly,User::MetricsJobis scheduled to run at minute 41 of every hour (41 * * * *). - System Maintenance: Larger maintenance tasks are scheduled less frequently. For example,
ConsolidateTrackedChangesJobruns every 3 hours to process data changes in batches.ActivateSeasonalMenusJobruns every 2 hours. - Financial Processes: Key financial operations are handled hourly.
Payout::CronProcessJobexecutes every hour to manage payouts.
Low-Frequency Jobs (Daily or less frequent)
A number of jobs are scheduled to run once or a few times per day, focusing on routine maintenance, less frequent notifications, and administrative tasks.
- Daily Maintenance: Jobs like
ClearOldOrdersJobrun daily to perform necessary table hygiene. - Notifications and Reminders: Time-specific reminders are sent daily. For example,
RemindFutureOrdersJobruns at 1:30 PM EST (30 13 * * *) andPackage::ApprovalReminderJobruns multiple times in the afternoon and evening (0 13,16,17,20 * * *). - Weekly and Monthly Tasks: Certain business processes are scheduled on a weekly or monthly basis.
BillPolleesJob, for instance, runs at 12:00 PM every Monday (0 12 * * 1), while invoice reminders are sent out on specific days of the month at 4:00 PM EST.AwardReferralsJobis scheduled for the first of the month at 4:00 PM (0 16 1 * *).
Recent Job Performance
The following table provides a snapshot of job execution statistics over a recent 4-hour period. This data offers insight into the operational load and performance of some of the most frequently run jobs.
| Name | Success | Failure | Total Execution Time (Seconds) | Average Execution Time (Seconds) |
|---|---|---|---|---|
SyncMenuItemModifiersJob | 242 | 0 | 1,890.88 | 7.81 |
SyncOptionDietaryTagsJob | 560 | 0 | 1,039.94 | 1.86 |
Order::MetricsJob | 4 | 0 | 397.17 | 99.29 |
PopulateOrderDeliveriesJob | 24 | 0 | 395.76 | 16.49 |
AssignUserPlacesJob | 240 | 0 | 362.19 | 1.51 |
Caterer::MetricsJob | 48 | 0 | 302.93 | 6.31 |
ConsolidateTrackedChangesJob | 2 | 0 | 293.92 | 146.96 |
IdentifyUpdatedUsersJob | 240 | 0 | 284.20 | 1.18 |
EnrichAttributionReportsJob | 24 | 0 | 221.58 | 9.23 |
SyncMenuCategoriesJob | 240 | 0 | 214.77 | 0.89 |
SyncMenuItemVariantsJob | 80 | 0 | 102.47 | 1.28 |
User::MetricsJob | 4 | 0 | 98.39 | 24.60 |
Package::RescoreJob | 16 | 0 | 98.29 | 6.14 |
PopulateKitchenSalesTaxJob | 1 | 0 | 93.68 | 93.68 |
NotifyNewPollsJob | 24 | 0 | 85.45 | 3.56 |
SyncKitchenGroupsJob | 16 | 0 | 76.10 | 4.76 |
ClearIgnoredPackageSyncsJob | 16 | 0 | 60.64 | 3.79 |
LockOrderItemSelectionsJob | 48 | 0 | 58.34 | 1.22 |
Payout::CronProcessJob | 4 | 0 | 57.83 | 14.46 |
ProvisionSalesOpportunitiesJob | 16 | 0 | 55.69 | 3.48 |