diff options
author | Kim Alvefur <zash@zash.se> | 2022-01-15 09:09:24 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2022-01-15 09:09:24 +0100 |
commit | e0e180aa9d9cac1e427ac23be49aca0c4059f755 (patch) | |
tree | 39a502fddbd20104aa7b40707b0791e0d45894c7 | |
parent | 9767804146df64fc0ce91896994616ff910fa8ee (diff) | |
download | prosody-e0e180aa9d9cac1e427ac23be49aca0c4059f755.tar.gz prosody-e0e180aa9d9cac1e427ac23be49aca0c4059f755.zip |
mod_cron: Allow for a small amount of timer drift
If the timer activates a bit early then a task might be just a few
seconds short of being allowed to run. This would run such a task rather
than wait another hour.
The value 0.5% chosen so that a weekly task does not run an entire hour
earlier than last time.
-rw-r--r-- | plugins/mod_cron.lua | 2 | ||||
-rw-r--r-- | teal-src/plugins/mod_cron.tl | 2 |
2 files changed, 2 insertions, 2 deletions
diff --git a/plugins/mod_cron.lua b/plugins/mod_cron.lua index f18d3a9a..f0c85615 100644 --- a/plugins/mod_cron.lua +++ b/plugins/mod_cron.lua @@ -40,7 +40,7 @@ function module.add_host(host_module) function host_module.unload() active_hosts[host_module.host] = nil; end end -local function should_run(when, last) return not last or last + periods[when] <= os.time() end +local function should_run(when, last) return not last or last + periods[when] * 0.995 <= os.time() end local function run_task(task) local started_at = os.time(); diff --git a/teal-src/plugins/mod_cron.tl b/teal-src/plugins/mod_cron.tl index 581c8c0a..1375a195 100644 --- a/teal-src/plugins/mod_cron.tl +++ b/teal-src/plugins/mod_cron.tl @@ -78,7 +78,7 @@ function module.add_host(host_module : moduleapi) end local function should_run(when : frequency, last : integer) : boolean - return not last or last + periods[when] <= os.time(); + return not last or last + periods[when]*0.995 <= os.time(); end local function run_task(task : task_spec) |