aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2024-02-20 17:31:17 +0000
committerMatthew Wild <mwild1@gmail.com>2024-02-20 17:31:17 +0000
commit69dc40ac35814f46b135fce1295e073a4659b6f0 (patch)
tree23e813bff25dfb73d08178faae7037b2487491e9
parent2ef771fff8ff2a2f764c3d0ea8397902f187d72e (diff)
downloadprosody-69dc40ac35814f46b135fce1295e073a4659b6f0.tar.gz
prosody-69dc40ac35814f46b135fce1295e073a4659b6f0.zip
mod_cron: Allow configuring various "internal" delay parameters
Notably, it is now possible to add a randomized spread factor to the check interval.
-rw-r--r--plugins/mod_cron.lua12
1 files changed, 10 insertions, 2 deletions
diff --git a/plugins/mod_cron.lua b/plugins/mod_cron.lua
index 077dc80e..158c3186 100644
--- a/plugins/mod_cron.lua
+++ b/plugins/mod_cron.lua
@@ -2,6 +2,10 @@ module:set_global();
local async = require("prosody.util.async");
+local cron_initial_delay = module:get_option_number("cron_initial_delay", 1);
+local cron_check_delay = module:get_option_number("cron_check_delay", 3600);
+local cron_spread_factor = module:get_option_number("cron_spread_factor", 0);
+
local active_hosts = {}
function module.add_host(host_module)
@@ -46,10 +50,14 @@ local function run_task(task)
task:save(started_at);
end
+local function spread(t, factor)
+ return t * (1 - factor + 2*factor*math.random());
+end
+
local task_runner = async.runner(run_task);
-scheduled = module:add_timer(1, function()
+scheduled = module:add_timer(cron_initial_delay, function()
module:log("info", "Running periodic tasks");
- local delay = 3600;
+ local delay = spread(cron_check_delay, cron_spread_factor);
for host in pairs(active_hosts) do
module:log("debug", "Running periodic tasks for host %s", host);
for _, task in ipairs(module:context(host):get_host_items("task")) do task_runner:run(task); end