aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2021-12-03 09:01:09 +0100
committerKim Alvefur <zash@zash.se>2021-12-03 09:01:09 +0100
commitd6070eea1ff8629f8bd71578ea4288e552b9e2db (patch)
treeb37f3099e728884684dfcf1c570233d0bb11ee60
parent914d3acbd53cc04aac4dc15b3d5efcbbde275f97 (diff)
downloadprosody-d6070eea1ff8629f8bd71578ea4288e552b9e2db.tar.gz
prosody-d6070eea1ff8629f8bd71578ea4288e552b9e2db.zip
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.
-rw-r--r--plugins/mod_cron.lua4
-rw-r--r--teal-src/plugins/mod_cron.tl6
2 files changed, 5 insertions, 5 deletions
diff --git a/plugins/mod_cron.lua b/plugins/mod_cron.lua
index 1255687e..e23d6815 100644
--- a/plugins/mod_cron.lua
+++ b/plugins/mod_cron.lua
@@ -22,9 +22,9 @@ function module.add_host(host_module)
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 --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