From ae344960f16393a01d0625a5e32e36b77aa3dce5 Mon Sep 17 00:00:00 2001 From: John Sully Date: Tue, 28 Jan 2020 21:39:56 -0500 Subject: [PATCH] CRON jobs were running half as often as required Former-commit-id: 1069d0b4bf39818cbd72d0bcbd168769244cf18f --- src/cron.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/cron.cpp b/src/cron.cpp index 72d26f5c3..fd777d43d 100644 --- a/src/cron.cpp +++ b/src/cron.cpp @@ -110,12 +110,20 @@ void executeCronJobExpireHook(const char *key, robj *o) if (job->startTime < (uint64_t)g_pserver->mstime) { // If we are more than one interval in the past then fast forward to - // the first interval still in the future - auto delta = g_pserver->mstime - job->startTime; - auto multiple = (delta / job->interval)+1; - job->startTime += job->interval * multiple; + // the first interval still in the future. If startTime wasn't zero align + // this to the original startTime, if it was zero align to now + if (job->startTime == job->interval) + { // startTime was 0 + job->startTime = g_pserver->mstime + job->interval; + } + else + { + auto delta = g_pserver->mstime - job->startTime; + auto multiple = (delta / job->interval)+1; + job->startTime += job->interval * multiple; + } } - setExpire(cFake, cFake->db, keyobj, keyobj, job->startTime + job->interval); + setExpire(cFake, cFake->db, keyobj, keyobj, job->startTime); } notifyKeyspaceEvent(NOTIFY_KEYEVENT, "CRON Executed", keyobj, dbId);