Mercurial > prosody-modules
comparison mod_firewall/definitions.lib.lua @ 6554:0002c727e918
mod_firewall: Use module:add_timer() for HTTP polling
This ensures that polling stops when the module is unloaded.
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sun, 24 May 2026 19:35:52 +0100 |
| parents | 7eec2bc67c26 |
| children |
comparison
equal
deleted
inserted
replaced
| 6553:7f3ad8a5b2ab | 6554:0002c727e918 |
|---|---|
| 3 -- luacheck: ignore 212 | 3 -- luacheck: ignore 212 |
| 4 | 4 |
| 5 local definition_handlers = {}; | 5 local definition_handlers = {}; |
| 6 | 6 |
| 7 local http = require "net.http"; | 7 local http = require "net.http"; |
| 8 local timer = require "util.timer"; | |
| 9 local set = require"util.set"; | 8 local set = require"util.set"; |
| 10 local new_throttle = require "util.throttle".create; | 9 local new_throttle = require "util.throttle".create; |
| 11 local hashes = require "util.hashes"; | 10 local hashes = require "util.hashes"; |
| 12 local jid = require "util.jid"; | 11 local jid = require "util.jid"; |
| 13 local lfs = require "lfs"; | 12 local lfs = require "lfs"; |
| 134 module:log("warn", "Failed to fetch list from <%s>: %d %s", url, code, tostring(body)); | 133 module:log("warn", "Failed to fetch list from <%s>: %d %s", url, code, tostring(body)); |
| 135 failure_count = failure_count + 1; | 134 failure_count = failure_count + 1; |
| 136 next_poll = retry_intervals[failure_count] or retry_intervals[#retry_intervals]; | 135 next_poll = retry_intervals[failure_count] or retry_intervals[#retry_intervals]; |
| 137 end | 136 end |
| 138 if next_poll > 0 then | 137 if next_poll > 0 then |
| 139 timer.add_task(next_poll+math.random(0, 60), update_list); | 138 return next_poll + math.random(0, 60); |
| 140 end | 139 end |
| 141 end); | 140 end); |
| 142 end | 141 end |
| 143 update_list(); | 142 local delay = update_list(); |
| 143 if delay then | |
| 144 module:add_timer(delay, update_list); | |
| 145 end | |
| 144 end; | 146 end; |
| 145 add = function () | 147 add = function () |
| 146 end; | 148 end; |
| 147 remove = function () | 149 remove = function () |
| 148 end; | 150 end; |
