Software /
code /
prosody
Comparison
plugins/mod_mam/mod_mam.lua @ 10682:62ef68f95b6f 0.11
mod_mam,mod_muc_mam: Allow other work to be performed during archive cleanup (fixes #1504)
This lets Prosody handle socket related work between each step in the
cleanup in order to prevent the server from being completely blocked
during this.
An async storage backend would not need this but those are currently
rare.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 11 Mar 2020 21:15:01 +0100 |
parent | 10567:3df479098696 |
child | 10683:2f0b7f1d5e75 |
comparison
equal
deleted
inserted
replaced
10681:e531273341d3 | 10682:62ef68f95b6f |
---|---|
360 if ok then | 360 if ok then |
361 last_date:set(username, date); | 361 last_date:set(username, date); |
362 end | 362 end |
363 end | 363 end |
364 | 364 |
365 cleanup_runner = require "util.async".runner(function () | 365 local async = require "util.async"; |
366 cleanup_runner = async.runner(function () | |
366 local users = {}; | 367 local users = {}; |
367 local cut_off = datestamp(os.time() - cleanup_after); | 368 local cut_off = datestamp(os.time() - cleanup_after); |
368 for date in cleanup_storage:users() do | 369 for date in cleanup_storage:users() do |
369 if date <= cut_off then | 370 if date <= cut_off then |
370 module:log("debug", "Messages from %q should be expired", date); | 371 module:log("debug", "Messages from %q should be expired", date); |
389 sum = sum + (tonumber(ok) or 0); | 390 sum = sum + (tonumber(ok) or 0); |
390 else | 391 else |
391 cleanup_map:set(cut_off, user, true); | 392 cleanup_map:set(cut_off, user, true); |
392 module:log("error", "Could not delete messages for user '%s': %s", user, err); | 393 module:log("error", "Could not delete messages for user '%s': %s", user, err); |
393 end | 394 end |
395 local wait, done = async.waiter(); | |
396 module:add_timer(0.01, done); | |
397 wait(); | |
394 end | 398 end |
395 module:log("info", "Deleted %d expired messages for %d users", sum, num_users); | 399 module:log("info", "Deleted %d expired messages for %d users", sum, num_users); |
396 end); | 400 end); |
397 | 401 |
398 cleanup_task = module:add_timer(1, function () | 402 cleanup_task = module:add_timer(1, function () |