Comparison

teal-src/plugins/mod_cron.tl @ 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
parent 12000:00c57684cf20
child 12002:cbed7d8d8f35
comparison
equal deleted inserted replaced
12000:00c57684cf20 12001:5a8c6f9a4583
53 task.last = last_run_times:get(nil, task.id); 53 task.last = last_run_times:get(nil, task.id);
54 end 54 end
55 task.save = save_task; 55 task.save = save_task;
56 module:log("debug", "%s task %s added, last run %s", task.when, task.id, 56 module:log("debug", "%s task %s added, last run %s", task.when, task.id,
57 task.last and datetime.datetime(task.last) or "never"); 57 task.last and datetime.datetime(task.last) or "never");
58 if task.last == nil and task.when == "daily" then 58 if task.last == nil then
59 -- initialize daily tasks to run at ~midnight UTC for now 59 -- initialize new tasks so e.g. daily tasks run at ~midnight UTC for now
60 local now = os.time(); 60 local now = os.time();
61 task.last = now - now % 86400; 61 task.last = now - now % periods[task.when];
62 end 62 end
63 return true; 63 return true;
64 end 64 end
65 65
66 local function task_removed(event : task_event) : boolean 66 local function task_removed(event : task_event) : boolean