mirror of
https://github.com/bjc/prosody.git
synced 2025-04-03 21:27:38 +03:00
core.moduleapi: Add API for adding daily or hourly tasks via mod_cron
This commit is contained in:
parent
630035a369
commit
7f2412db5c
2 changed files with 17 additions and 0 deletions
|
@ -52,6 +52,8 @@ files["plugins/"] = {
|
|||
"module.add_identity",
|
||||
"module.add_item",
|
||||
"module.add_timer",
|
||||
"module.daily",
|
||||
"module.hourly",
|
||||
"module.broadcast",
|
||||
"module.context",
|
||||
"module.depends",
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue