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.
--- 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
--- 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