Changeset

12001:5a8c6f9a4583

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.
author Kim Alvefur <zash@zash.se>
date Fri, 03 Dec 2021 09:01:09 +0100
parents 12000:00c57684cf20
children 12002:cbed7d8d8f35
files plugins/mod_cron.lua teal-src/plugins/mod_cron.tl
diffstat 2 files changed, 5 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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