aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2022-06-11 22:15:14 +0100
committerMatthew Wild <mwild1@gmail.com>2022-06-11 22:15:14 +0100
commit029e0934783a60cf0be8c08e982440205fa9d337 (patch)
treed6e4b6be0edd0f43cd812dc88cfcc852ec6023ad /util
parent49a9d5e4274c26272761656d3fdaa6b2509c90f5 (diff)
downloadprosody-029e0934783a60cf0be8c08e982440205fa9d337.tar.gz
prosody-029e0934783a60cf0be8c08e982440205fa9d337.zip
util.watchdog: Allow :reset() to restart a cancelled watchdog
Diffstat (limited to 'util')
-rw-r--r--util/watchdog.lua11
1 files changed, 6 insertions, 5 deletions
diff --git a/util/watchdog.lua b/util/watchdog.lua
index 1d30f22b..6eb2e602 100644
--- a/util/watchdog.lua
+++ b/util/watchdog.lua
@@ -1,6 +1,5 @@
local timer = require "util.timer";
local setmetatable = setmetatable;
-local os_time = os.time;
local _ENV = nil;
-- luacheck: std none
@@ -15,16 +14,18 @@ local function new(timeout, callback)
timer_id = nil;
}, watchdog_mt);
- watchdog.timer_id = timer.add_task(timeout+1, function ()
- return watchdog:callback();
- end);
+ watchdog:reset(); -- Kick things off
return watchdog;
end
function watchdog_methods:reset()
if self.timer_id then
- timer.reschedule(self.timer_id, self.timeout);
+ timer.reschedule(self.timer_id, self.timeout+1);
+ else
+ self.timer_id = timer.add_task(self.timeout+1, function ()
+ return self:callback();
+ end);
end
end