aboutsummaryrefslogtreecommitdiffstats
path: root/core/moduleapi.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2021-11-21 18:13:21 +0100
committerKim Alvefur <zash@zash.se>2021-11-21 18:13:21 +0100
commit7f2412db5c6ce5e85347ba558a79cc1ff8462605 (patch)
tree034f48df7bbe72ad099ab2d6488a0e928bad1efb /core/moduleapi.lua
parent630035a369f5e5fe9783435011cda4bb78e7f889 (diff)
downloadprosody-7f2412db5c6ce5e85347ba558a79cc1ff8462605.tar.gz
prosody-7f2412db5c6ce5e85347ba558a79cc1ff8462605.zip
core.moduleapi: Add API for adding daily or hourly tasks via mod_cron
Diffstat (limited to 'core/moduleapi.lua')
-rw-r--r--core/moduleapi.lua15
1 files changed, 15 insertions, 0 deletions
diff --git a/core/moduleapi.lua b/core/moduleapi.lua
index 40c091ad..82b1faf3 100644
--- a/core/moduleapi.lua
+++ b/core/moduleapi.lua
@@ -506,6 +506,21 @@ function api:add_timer(delay, callback, ...)
return setmetatable(t, timer_mt);
end
+function api:cron(task_spec)
+ self:depends("cron");
+ self:add_item("task", task_spec);
+end
+
+function api:hourly(name, fun)
+ if type(name) == "function" then fun, name = name, nil; end
+ self:cron({ name = name; when = "hourly"; run = fun });
+end
+
+function api:daily(name, fun)
+ if type(name) == "function" then fun, name = name, nil; end
+ self:cron({ name = name; when = "daily"; run = fun });
+end
+
local path_sep = package.config:sub(1,1);
function api:get_directory()
return self.resource_path or self.path and (self.path:gsub("%"..path_sep.."[^"..path_sep.."]*$", "")) or nil;