Software /
code /
prosody
Comparison
plugins/mod_mam/mod_mam.lua @ 11988:18c0ca5fcbb8
mod_mam: Switch to new cron API
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 21 Nov 2021 18:16:03 +0100 |
parent | 11968:6e1af07921d1 |
child | 12030:9f8206e99b89 |
comparison
equal
deleted
inserted
replaced
11987:4b519c575ad0 | 11988:18c0ca5fcbb8 |
---|---|
41 | 41 |
42 local archive_store = module:get_option_string("archive_store", "archive"); | 42 local archive_store = module:get_option_string("archive_store", "archive"); |
43 local archive = module:open_store(archive_store, "archive"); | 43 local archive = module:open_store(archive_store, "archive"); |
44 | 44 |
45 local cleanup_after = module:get_option_string("archive_expires_after", "1w"); | 45 local cleanup_after = module:get_option_string("archive_expires_after", "1w"); |
46 local cleanup_interval = module:get_option_number("archive_cleanup_interval", 4 * 60 * 60); | |
47 local archive_item_limit = module:get_option_number("storage_archive_item_limit", archive.caps and archive.caps.quota or 1000); | 46 local archive_item_limit = module:get_option_number("storage_archive_item_limit", archive.caps and archive.caps.quota or 1000); |
48 local archive_truncate = math.floor(archive_item_limit * 0.99); | 47 local archive_truncate = math.floor(archive_item_limit * 0.99); |
49 | 48 |
50 if not archive.find then | 49 if not archive.find then |
51 error("mod_"..(archive._provided_by or archive.name and "storage_"..archive.name).." does not support archiving\n" | 50 error("mod_"..(archive._provided_by or archive.name and "storage_"..archive.name).." does not support archiving\n" |
522 end | 521 end |
523 | 522 |
524 local cleanup_time = module:measure("cleanup", "times"); | 523 local cleanup_time = module:measure("cleanup", "times"); |
525 | 524 |
526 local async = require "util.async"; | 525 local async = require "util.async"; |
527 cleanup_runner = async.runner(function () | 526 module:daily("Remove expired messages", function () |
528 local cleanup_done = cleanup_time(); | 527 local cleanup_done = cleanup_time(); |
529 | 528 |
530 if archive.caps and archive.caps.wildcard_delete then | 529 if archive.caps and archive.caps.wildcard_delete then |
531 local ok, err = archive:delete(true, { ["end"] = os.time() - cleanup_after }) | 530 local ok, err = archive:delete(true, { ["end"] = os.time() - cleanup_after }) |
532 if ok then | 531 if ok then |
578 end | 577 end |
579 module:log("info", "Deleted %d expired messages for %d users", sum, num_users); | 578 module:log("info", "Deleted %d expired messages for %d users", sum, num_users); |
580 cleanup_done(); | 579 cleanup_done(); |
581 end); | 580 end); |
582 | 581 |
583 cleanup_task = module:add_timer(1, function () | |
584 cleanup_runner:run(true); | |
585 return cleanup_interval; | |
586 end); | |
587 else | 582 else |
588 module:log("debug", "Archive expiry disabled"); | 583 module:log("debug", "Archive expiry disabled"); |
589 -- Don't ask the backend to count the potentially unbounded number of items, | 584 -- Don't ask the backend to count the potentially unbounded number of items, |
590 -- it'll get slow. | 585 -- it'll get slow. |
591 use_total = module:get_option_boolean("mam_include_total", false); | 586 use_total = module:get_option_boolean("mam_include_total", false); |