diff options
author | Kim Alvefur <zash@zash.se> | 2023-10-22 18:58:02 +0200 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2023-10-22 18:58:02 +0200 |
commit | 7b882e440590cd8a93b34ee00809ab742fc0c60d (patch) | |
tree | ae41a7cc883ba32fdc9f85dd7fefa05053f39530 /teal-src/prosody/plugins | |
parent | 76bf26057e3bf6fe5620114bc438512bba9e9afe (diff) | |
download | prosody-7b882e440590cd8a93b34ee00809ab742fc0c60d.tar.gz prosody-7b882e440590cd8a93b34ee00809ab742fc0c60d.zip |
mod_cron: Make task frequencies configurable in overly generic manner
Requested feature for many modules, notably MAM and file sharing.
Diffstat (limited to 'teal-src/prosody/plugins')
-rw-r--r-- | teal-src/prosody/plugins/mod_cron.tl | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/teal-src/prosody/plugins/mod_cron.tl b/teal-src/prosody/plugins/mod_cron.tl index 6c69ef7d..c5a02cc9 100644 --- a/teal-src/prosody/plugins/mod_cron.tl +++ b/teal-src/prosody/plugins/mod_cron.tl @@ -18,6 +18,7 @@ local record task_spec id : string -- unique id name : string -- name or short description when : frequency + period : number last : integer run : function (task_spec, integer) save : function (task_spec, integer) @@ -29,8 +30,6 @@ local record task_event item : task_spec end -local periods : { frequency : integer } = { hourly = 3600, daily = 86400, weekly = 7*86400 } - local active_hosts : { string : boolean } = { } function module.add_host(host_module : moduleapi) @@ -56,6 +55,7 @@ function module.add_host(host_module : moduleapi) if task.id == nil then task.id = event.source.name .. "/" .. task.name:gsub("%W", "_"):lower(); end + task.period = host_module:get_option_period(task.id:gsub("/", "_") .. "_period", "1" .. task.when, 60, 86400*7*53); task.restore = restore_task; task.save = save_task; module:log("debug", "%s task %s added", task.when, task.id); @@ -75,13 +75,13 @@ function module.add_host(host_module : moduleapi) end end -local function should_run(when : frequency, last : integer) : boolean - return not last or last + periods[when]*0.995 <= os.time(); +local function should_run(task : task_spec, last : integer) : boolean + return not last or last + task.period * 0.995 <= os.time(); end local function run_task(task : task_spec) task:restore(); - if not should_run(task.when, task.last) then + if not should_run(task, task.last) then return; end local started_at = os.time(); |