Comparison

plugins/mod_cron.lua @ 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
20 if task.id == nil then task.id = event.source.name .. "/" .. task.name:gsub("%W", "_"):lower(); end 20 if task.id == nil then task.id = event.source.name .. "/" .. task.name:gsub("%W", "_"):lower(); end
21 if task.last == nil then task.last = last_run_times:get(nil, task.id); end 21 if task.last == nil then task.last = last_run_times:get(nil, task.id); end
22 task.save = save_task; 22 task.save = save_task;
23 module:log("debug", "%s task %s added, last run %s", task.when, task.id, 23 module:log("debug", "%s task %s added, last run %s", task.when, task.id,
24 task.last and datetime.datetime(task.last) or "never"); 24 task.last and datetime.datetime(task.last) or "never");
25 if task.last == nil and task.when == "daily" then 25 if task.last == nil then
26 local now = os.time(); 26 local now = os.time();
27 task.last = now - now % 86400; 27 task.last = now - now % periods[task.when];
28 end 28 end
29 return true 29 return true
30 end 30 end
31 31
32 local function task_removed(event) 32 local function task_removed(event)