Software /
code /
prosody
Comparison
plugins/mod_cron.lua @ 12000:00c57684cf20
mod_cron: Follow convention of imports at the top
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 03 Dec 2021 08:57:40 +0100 |
parent | 11995:bbd3ac65640d |
child | 12001:5a8c6f9a4583 |
comparison
equal
deleted
inserted
replaced
11999:9d2eab56f124 | 12000:00c57684cf20 |
---|---|
1 module:set_global(); | 1 module:set_global(); |
2 | 2 |
3 local async = require("util.async"); | 3 local async = require("util.async"); |
4 local datetime = require("util.datetime"); | |
4 | 5 |
5 local periods = { hourly = 3600; daily = 86400 } | 6 local periods = { hourly = 3600; daily = 86400 } |
6 | 7 |
7 local active_hosts = {} | 8 local active_hosts = {} |
8 | 9 |
18 if task.name == nil then task.name = task.when; end | 19 if task.name == nil then task.name = task.when; end |
19 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 |
20 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 |
21 task.save = save_task; | 22 task.save = save_task; |
22 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, |
23 task.last and require("util.datetime").datetime(task.last) or "never"); | 24 task.last and datetime.datetime(task.last) or "never"); |
24 if task.last == nil and task.when == "daily" then | 25 if task.last == nil and task.when == "daily" then |
25 local now = os.time(); | 26 local now = os.time(); |
26 task.last = now - now % 86400; | 27 task.last = now - now % 86400; |
27 end | 28 end |
28 return true | 29 return true |