Comparison

mod_mam/mod_mam.lua @ 2039:464edd03099a

mod_mam: Add a bit of randomness to cleanup intervals to keep some time between multiple instances
author Kim Alvefur <zash@zash.se>
date Tue, 02 Feb 2016 16:26:21 +0100
parent 2033:acf86edeb1cc
child 2042:752eee154891
comparison
equal deleted inserted replaced
2038:a85b5c3791dc 2039:464edd03099a
296 for user in um.users(module.host) do 296 for user in um.users(module.host) do
297 cleanup[user] = true; 297 cleanup[user] = true;
298 end 298 end
299 end); 299 end);
300 300
301 module:add_timer(10, function() 301 module:add_timer(math.random(10, 60), function()
302 local user = next(cleanup); 302 local user = next(cleanup);
303 if user then 303 if user then
304 module:log("debug", "Removing old messages for user %q", user); 304 module:log("debug", "Removing old messages for user %q", user);
305 local ok, err = archive:delete(user, { ["end"] = os.time() - cleanup_after; }) 305 local ok, err = archive:delete(user, { ["end"] = os.time() - cleanup_after; })
306 if not ok then 306 if not ok then
307 module:log("warn", "Could not expire archives for user %s: %s", user, err); 307 module:log("warn", "Could not expire archives for user %s: %s", user, err);
308 end 308 end
309 cleanup[user] = nil; 309 cleanup[user] = nil;
310 end 310 end
311 return cleanup_interval; 311 return math.random(cleanup_interval, cleanup_interval * 2);
312 end); 312 end);
313 end 313 end
314 314
315 -- Stanzas sent by local clients 315 -- Stanzas sent by local clients
316 module:hook("pre-message/bare", c2s_message_handler, 2); 316 module:hook("pre-message/bare", c2s_message_handler, 2);