util.x509: Only collect commonNames that pass idna
[prosody.git] / util / watchdog.lua
blob516e60e4cbad131104e3f11956c24f5a2cdc7d46
1 local timer = require "util.timer";
2 local setmetatable = setmetatable;
3 local os_time = os.time;
5 local _ENV = nil;
6 -- luacheck: std none
8 local watchdog_methods = {};
9 local watchdog_mt = { __index = watchdog_methods };
11 local function new(timeout, callback)
12 local watchdog = setmetatable({ timeout = timeout, last_reset = os_time(), callback = callback }, watchdog_mt);
13 timer.add_task(timeout+1, function (current_time)
14 local last_reset = watchdog.last_reset;
15 if not last_reset then
16 return;
17 end
18 local time_left = (last_reset + timeout) - current_time;
19 if time_left < 0 then
20 return watchdog:callback();
21 end
22 return time_left + 1;
23 end);
24 return watchdog;
25 end
27 function watchdog_methods:reset()
28 self.last_reset = os_time();
29 end
31 function watchdog_methods:cancel()
32 self.last_reset = nil;
33 end
35 return {
36 new = new;