CRON jobs were running half as often as required

Former-commit-id: 1069d0b4bf39818cbd72d0bcbd168769244cf18f
This commit is contained in:
John Sully 2020-01-28 21:39:56 -05:00
parent 3be0eac7b6
commit ae344960f1

View File

@ -110,12 +110,20 @@ void executeCronJobExpireHook(const char *key, robj *o)
if (job->startTime < (uint64_t)g_pserver->mstime) if (job->startTime < (uint64_t)g_pserver->mstime)
{ {
// If we are more than one interval in the past then fast forward to // If we are more than one interval in the past then fast forward to
// the first interval still in the future // the first interval still in the future. If startTime wasn't zero align
auto delta = g_pserver->mstime - job->startTime; // this to the original startTime, if it was zero align to now
auto multiple = (delta / job->interval)+1; if (job->startTime == job->interval)
job->startTime += job->interval * multiple; { // 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); notifyKeyspaceEvent(NOTIFY_KEYEVENT, "CRON Executed", keyobj, dbId);