mod_cron: Initialize timestamp of new tasks to start of period
authorKim Alvefur <zash@zash.se>
Fri, 03 Dec 2021 09:01:09 +0100
changeset 12005 5a8c6f9a4583
parent 12004 00c57684cf20
child 12006 cbed7d8d8f35
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.
plugins/mod_cron.lua
teal-src/plugins/mod_cron.tl
--- 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