Changeset

11995:bbd3ac65640d

mod_cron: Initialize daily tasks so they run around midnight UTC Eventually the goal is to have daily tasks run while there is little activity, but that will vary with the server and the usage patterns of its users. This is a start anyway.
author Kim Alvefur <zash@zash.se>
date Fri, 03 Dec 2021 00:11:31 +0100
parents 11994:f9b2325f6b50
children 11996:3dd7886f9342
files plugins/mod_cron.lua teal-src/plugins/mod_cron.tl
diffstat 2 files changed, 9 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_cron.lua	Tue Nov 30 00:55:54 2021 +0100
+++ b/plugins/mod_cron.lua	Fri Dec 03 00:11:31 2021 +0100
@@ -21,6 +21,10 @@
 		task.save = save_task;
 		module:log("debug", "%s task %s added, last run %s", task.when, task.id,
 			task.last and require("util.datetime").datetime(task.last) or "never");
+		if task.last == nil and task.when == "daily" then
+			local now = os.time();
+			task.last = now - now % 86400;
+		end
 		return true
 	end
 
--- a/teal-src/plugins/mod_cron.tl	Tue Nov 30 00:55:54 2021 +0100
+++ b/teal-src/plugins/mod_cron.tl	Fri Dec 03 00:11:31 2021 +0100
@@ -54,6 +54,11 @@
 		task.save = save_task;
 		module:log("debug", "%s task %s added, last run %s", task.when, task.id,
 			task.last and require"util.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
+			local now = os.time();
+			task.last = now - now % 86400;
+		end
 		return true;
 	end