Software /
code /
prosody
Comparison
plugins/mod_http_file_share.lua @ 11990:6f4790b8deec
mod_http_file_share: Switch to mod_cron for periodic tasks
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 22 Nov 2021 14:54:32 +0100 |
parent | 11873:2b85e4e7d389 |
child | 11992:876e1b6d6ae4 |
comparison
equal
deleted
inserted
replaced
11989:871100cdbbad | 11990:6f4790b8deec |
---|---|
455 wait(); | 455 wait(); |
456 end | 456 end |
457 | 457 |
458 local prune_start = module:measure("prune", "times"); | 458 local prune_start = module:measure("prune", "times"); |
459 | 459 |
460 local reaper_task = async.runner(function(boundary_time) | 460 module:daily("Remove expired files", function(_, boundary_time) |
461 local prune_done = prune_start(); | 461 local prune_done = prune_start(); |
462 local iter, total = assert(uploads:find(nil, {["end"] = boundary_time; total = true})); | 462 local iter, total = assert(uploads:find(nil, {["end"] = boundary_time; total = true})); |
463 | 463 |
464 if total == 0 then | 464 if total == 0 then |
465 module:log("info", "No expired uploaded files to prune"); | 465 module:log("info", "No expired uploaded files to prune"); |
466 prune_done(); | 466 prune_done(); |
467 return; | 467 return; |
468 end | 468 end |
469 | 469 |
470 module:log("info", "Pruning expired files uploaded earlier than %s", dt.datetime(boundary_time)); | 470 module:log("info", "Pruning expired files uploaded earlier than %s", dt.datetime(boundary_time)); |
471 if total_storage_limit then | 471 if total_storage_usage then |
472 module:log("debug", "Global quota %s / %s", B(total_storage_usage), B(total_storage_limit)); | 472 module:log("debug", "Global quota %s / %s", B(total_storage_usage), B(total_storage_limit)); |
473 elseif total_storage_limit then | |
474 module:log("debug", "Global quota %s / %s", "not yet calculated", B(total_storage_limit)); | |
473 end | 475 end |
474 | 476 |
475 local obsolete_uploads = array(); | 477 local obsolete_uploads = array(); |
476 local i = 0; | 478 local i = 0; |
477 local size_sum = 0; | 479 local size_sum = 0; |
531 end | 533 end |
532 end | 534 end |
533 | 535 |
534 prune_done(); | 536 prune_done(); |
535 end); | 537 end); |
536 | |
537 module:add_timer(5, function () | |
538 reaper_task:run(os.time()-expiry); | |
539 return 60*60; | |
540 end); | |
541 end | 538 end |
542 | 539 |
543 if total_storage_limit then | 540 if total_storage_limit then |
544 local async = require "util.async"; | |
545 | |
546 local summary_start = module:measure("summary", "times"); | 541 local summary_start = module:measure("summary", "times"); |
547 | 542 |
548 local summarizer_task = async.runner(function() | 543 module:daily("Global quota check", function() |
549 local summary_done = summary_start(); | 544 local summary_done = summary_start(); |
550 local iter = assert(uploads:find(nil)); | 545 local iter = assert(uploads:find(nil)); |
551 | 546 |
552 local count, sum = 0, 0; | 547 local count, sum = 0, 0; |
553 for _, file in iter do | 548 for _, file in iter do |
559 total_storage_usage = sum; | 554 total_storage_usage = sum; |
560 module:log("debug", "Global quota %s / %s", B(total_storage_usage), B(total_storage_limit)); | 555 module:log("debug", "Global quota %s / %s", B(total_storage_usage), B(total_storage_limit)); |
561 summary_done(); | 556 summary_done(); |
562 end); | 557 end); |
563 | 558 |
564 module:add_timer(1, function() | |
565 summarizer_task:run(true); | |
566 return 11 * 60 * 60; | |
567 end); | |
568 end | 559 end |
569 | 560 |
570 -- Reachable from the console | 561 -- Reachable from the console |
571 function check_files(query) | 562 function check_files(query) |
572 local issues = {}; | 563 local issues = {}; |