aboutsummaryrefslogtreecommitdiffstats
path: root/teal-src/prosody
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2024-02-24 14:32:59 +0100
committerKim Alvefur <zash@zash.se>2024-02-24 14:32:59 +0100
commitcef925e9a515861124482af9d606658de73ce0ba (patch)
treeafb7657de6ce6e49de388f2219af5d52b26a90f0 /teal-src/prosody
parent761643abcc02b20378d0e71ed6dbeef90d858e7e (diff)
downloadprosody-cef925e9a515861124482af9d606658de73ce0ba.tar.gz
prosody-cef925e9a515861124482af9d606658de73ce0ba.zip
mod_cron: Sync Teal source with 92301fa7a673
Yeah, it's weird to have two versions. Needing more build dependencies is also something we want to avoid, so here we are.
Diffstat (limited to 'teal-src/prosody')
-rw-r--r--teal-src/prosody/plugins/mod_cron.tl12
1 files changed, 10 insertions, 2 deletions
diff --git a/teal-src/prosody/plugins/mod_cron.tl b/teal-src/prosody/plugins/mod_cron.tl
index 9c6f1601..13f4a588 100644
--- a/teal-src/prosody/plugins/mod_cron.tl
+++ b/teal-src/prosody/plugins/mod_cron.tl
@@ -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 record map_store<K,V>
-- TODO move to somewhere sensible
get : function (map_store<K,V>, string, K) : V
@@ -90,10 +94,14 @@ local function run_task(task : task_spec)
task:save(started_at);
end
+local function spread(t : number, factor : number) : number
+ return t * (1 - factor + 2*factor*math.random());
+end
+
local task_runner : async.runner_t<task_spec> = async.runner(run_task);
-scheduled = module:add_timer(1, function() : integer
+scheduled = module:add_timer(cron_initial_delay, function() : number
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") as { task_spec } ) do