From f98a6e22450ad92ada62df7cbeb34dec16d92fa7 Mon Sep 17 00:00:00 2001 From: Selt <83926739+seltonmt012@users.noreply.github.com> Date: Mon, 27 Jul 2026 21:17:12 +0200 Subject: [PATCH] fix(cron): keep the scheduler alive when a job errors Registered jobs are third party callbacks and were invoked bare. An error inside one propagates out of OnTime into Tick, so Tick never reaches its SetTimeout(60000, Tick) at the end and nothing ever reschedules it. From that moment cron is dead for every resource on the server - paychecks, cleanups, anything registered through cron:runAt - until a restart. The operator sees one stack trace and then silence. Wrapping the callback keeps the loop and the reschedule intact, and names the job that failed. Simulated the scheduler chain in standalone Lua with three jobs where the first raises: before, the tick died before SetTimeout and the two later jobs never ran again; after, the failure is reported and both later jobs fire. --- [core]/cron/server/main.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/[core]/cron/server/main.lua b/[core]/cron/server/main.lua index 51da085d..7044069d 100644 --- a/[core]/cron/server/main.lua +++ b/[core]/cron/server/main.lua @@ -38,7 +38,10 @@ function OnTime(timestamp) if timestamp >= scheduledTimestamp and (not lastTimestamp or lastTimestamp < scheduledTimestamp) then local d = os.date('*t', scheduledTimestamp).wday - cronJobs[i].cb(d, cronJobs[i].h, cronJobs[i].m) + + if not pcall(cronJobs[i].cb, d, cronJobs[i].h, cronJobs[i].m) then + print(("[^1ERROR^7] cron job at ^5%02d:%02d^7 errored, skipping it"):format(cronJobs[i].h, cronJobs[i].m)) + end end end end