# HG changeset patch # User Kim Alvefur # Date 1638518469 -3600 # Node ID 5a8c6f9a4583f3a947358665f299fc5e81bf04ae # Parent 00c57684cf2087d51ba3aefb04cff15fa746016a 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. diff -r 00c57684cf20 -r 5a8c6f9a4583 plugins/mod_cron.lua --- a/plugins/mod_cron.lua Fri Dec 03 08:57:40 2021 +0100 +++ b/plugins/mod_cron.lua Fri Dec 03 09:01:09 2021 +0100 @@ -22,9 +22,9 @@ 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 + if task.last == nil then local now = os.time(); - task.last = now - now % 86400; + task.last = now - now % periods[task.when]; end return true end diff -r 00c57684cf20 -r 5a8c6f9a4583 teal-src/plugins/mod_cron.tl --- a/teal-src/plugins/mod_cron.tl Fri Dec 03 08:57:40 2021 +0100 +++ b/teal-src/plugins/mod_cron.tl Fri Dec 03 09:01:09 2021 +0100 @@ -55,10 +55,10 @@ 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