# HG changeset patch # User Kim Alvefur # Date 1642234164 -3600 # Node ID 7f25ac9d8f0d919b7afd6fb417ba3a8749eed13b # Parent 708769a4c5da2a83cb682c59174e978aac3b6fd1 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. diff -r 708769a4c5da -r 7f25ac9d8f0d plugins/mod_cron.lua --- a/plugins/mod_cron.lua Fri Jan 14 17:00:13 2022 +0000 +++ b/plugins/mod_cron.lua Sat Jan 15 09:09:24 2022 +0100 @@ -40,7 +40,7 @@ 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 -r 708769a4c5da -r 7f25ac9d8f0d teal-src/plugins/mod_cron.tl --- a/teal-src/plugins/mod_cron.tl Fri Jan 14 17:00:13 2022 +0000 +++ b/teal-src/plugins/mod_cron.tl Sat Jan 15 09:09:24 2022 +0100 @@ -78,7 +78,7 @@ 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)