[ 'interval' => 86400, // 24 hours 'last_run' => 0, 'next_run' => 0, 'time' => '15:00', 'function' => 'checkUnfulfilledBookings', ], 'SyncBookings' => [ 'interval' => 60, // 1 minute 'last_run' => 0, 'next_run' => 0, 'function' => 'syncBookings', ], 'SyncLogs' => [ 'interval' => 300, // 5 minutes 'last_run' => 0, 'next_run' => 0, 'function' => 'syncLogsToDatabase', ], 'SyncUserEconomicCustomerDiscounts' => [ 'interval' => 600, // 10 minutes 'last_run' => 0, 'next_run' => 0, 'function' => 'SyncUserEconomicCustomerDiscounts', ], 'SyncUserEconomicCustomerDetails' => [ 'interval' => 43200, // 12 hours 'last_run' => 0, 'next_run' => 0, 'function' => 'SyncUserEconomicCustomerDetails', ], ]; function checkUnfulfilledBookings(): void { $bookings_o = new bookings_o(); $bookings_o->checkUnfulfilledBookings(); } function syncBookings(): void { $bookings_o = new bookings_o(); $response_cron[] = $bookings_o->syncBookings(); } function syncLogsToDatabase(): void { $logs_o = new logs_o(); $logs_o->syncLogsToDatabase(); } function SyncUserEconomicCustomerDiscounts(): void { $users_o = new users_o(); $users_o->clearAllUsersEconomicCustomerDiscountsFromCache(); } function SyncUserEconomicCustomerDetails(): void { $users_o = new users_o(); $users_o->clearAllUsersEconomicCustomerDetailsFromCache(); $users_o->syncAllUsersEconomicCustomerDetails(); } foreach ( $cron_tasks as $task => $data ) { $lastRun = redis->get_last_crond_run($task) === null ? 0 : redis->get_last_crond_run($task); $nextRun = $lastRun + $data['interval']; $cron_tasks[$task]['last_run'] = $lastRun; $cron_tasks[$task]['next_run'] = $nextRun; if ($nextRun <= time()) { $data['function'](); redis->set_last_crond_run($task, time()); } else { $response_cron[] = $task . ' is not due to run yet, next run is at ' . date('Y-m-d H:i:s', $nextRun) . ' (' . ($nextRun - time()) . ' seconds)'; } }