Software /
code /
prosody
Comparison
plugins/mod_mam/mod_mam.lua @ 9757:03ed7f10d8da
mod_mam: Measure how long it takes to run the message expiry job job
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 06 Jan 2019 09:34:59 +0100 |
parent | 9752:5cc2765c3ce4 |
child | 9758:d4a534e6bd7c |
comparison
equal
deleted
inserted
replaced
9756:38f7bde4cfe0 | 9757:03ed7f10d8da |
---|---|
349 -- outside the cleanup range. | 349 -- outside the cleanup range. |
350 | 350 |
351 function schedule_cleanup(username, date) | 351 function schedule_cleanup(username, date) |
352 cleanup_map:set(date or datestamp(), username, true); | 352 cleanup_map:set(date or datestamp(), username, true); |
353 end | 353 end |
354 local cleanup_time = module:measure("cleanup", "times"); | |
354 | 355 |
355 cleanup_runner = require "util.async".runner(function () | 356 cleanup_runner = require "util.async".runner(function () |
357 local cleanup_done = cleanup_time(); | |
356 local users = {}; | 358 local users = {}; |
357 local cut_off = datestamp(os.time() - cleanup_after); | 359 local cut_off = datestamp(os.time() - cleanup_after); |
358 for date in cleanup_storage:users() do | 360 for date in cleanup_storage:users() do |
359 if date < cut_off then | 361 if date < cut_off then |
360 module:log("debug", "Messages from %q should be expired", date); | 362 module:log("debug", "Messages from %q should be expired", date); |
374 num_users = num_users + 1; | 376 num_users = num_users + 1; |
375 sum = sum + tonumber(ok) or 0; | 377 sum = sum + tonumber(ok) or 0; |
376 end | 378 end |
377 end | 379 end |
378 module:log("info", "Deleted %d expired messages for %d users", sum, num_users); | 380 module:log("info", "Deleted %d expired messages for %d users", sum, num_users); |
381 cleanup_done(); | |
379 end); | 382 end); |
380 | 383 |
381 cleanup_task = module:add_timer(1, function () | 384 cleanup_task = module:add_timer(1, function () |
382 cleanup_runner:run(true); | 385 cleanup_runner:run(true); |
383 return cleanup_interval; | 386 return cleanup_interval; |