From 1b5e29c62b449c0a1a5cb3d7954fd8307821b0e1 Mon Sep 17 00:00:00 2001 From: Selt <83926739+seltonmt012@users.noreply.github.com> Date: Tue, 28 Jul 2026 00:44:30 +0200 Subject: [PATCH] fix(cron): build the scheduled time from the day the job belongs to OnTime always built scheduledTimestamp from the date of the current tick, so a tick that skipped the 23:59 minute compared it against 23:59 of the next day. The run was dropped without a trace. Fall back to the previous day when the scheduled time lands in the future. --- [core]/cron/server/main.lua | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/[core]/cron/server/main.lua b/[core]/cron/server/main.lua index 51da085d..1b613aa7 100644 --- a/[core]/cron/server/main.lua +++ b/[core]/cron/server/main.lua @@ -26,17 +26,25 @@ end ---@param timestamp number function OnTime(timestamp) - for i = 1, #cronJobs, 1 do - local scheduledTimestamp = os.time({ - hour = cronJobs[i].h, - min = cronJobs[i].m, + local function scheduledAt(job, dayOffset) + return os.time({ + hour = job.h, + min = job.m, sec = 0, -- Assuming tasks run at the start of the minute - day = os.date("%d", timestamp), + day = os.date("%d", timestamp) + dayOffset, month = os.date("%m", timestamp), year = os.date("%Y", timestamp), }) + end - if timestamp >= scheduledTimestamp and (not lastTimestamp or lastTimestamp < scheduledTimestamp) then + for i = 1, #cronJobs, 1 do + local scheduledTimestamp = scheduledAt(cronJobs[i], 0) + + if scheduledTimestamp > timestamp then + scheduledTimestamp = scheduledAt(cronJobs[i], -1) + end + + if not lastTimestamp or lastTimestamp < scheduledTimestamp then local d = os.date('*t', scheduledTimestamp).wday cronJobs[i].cb(d, cronJobs[i].h, cronJobs[i].m) end