From d6070eea1ff8629f8bd71578ea4288e552b9e2db Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 3 Dec 2021 09:01:09 +0100 Subject: mod_cron: Initialize timestamp of new tasks to start of period Makes it more generic so new periods (e.g. weekly etc) can be added easily. --- teal-src/plugins/mod_cron.tl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'teal-src/plugins') diff --git a/teal-src/plugins/mod_cron.tl b/teal-src/plugins/mod_cron.tl index 8d1fa452..7a2af971 100644 --- a/teal-src/plugins/mod_cron.tl +++ b/teal-src/plugins/mod_cron.tl @@ -55,10 +55,10 @@ function module.add_host(host_module : moduleapi) task.save = save_task; module:log("debug", "%s task %s added, last run %s", task.when, task.id, task.last and datetime.datetime(task.last) or "never"); - if task.last == nil and task.when == "daily" then - -- initialize daily tasks to run at ~midnight UTC for now + if task.last == nil then + -- initialize new tasks so e.g. daily tasks run at ~midnight UTC for now local now = os.time(); - task.last = now - now % 86400; + task.last = now - now % periods[task.when]; end return true; end -- cgit v1.2.3