Changeset

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
parents 11989:871100cdbbad
children 11991:bef2a59b00d1
files plugins/mod_http_file_share.lua
diffstat 1 files changed, 5 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_http_file_share.lua	Mon Nov 22 14:49:05 2021 +0100
+++ b/plugins/mod_http_file_share.lua	Mon Nov 22 14:54:32 2021 +0100
@@ -457,7 +457,7 @@
 
 	local prune_start = module:measure("prune", "times");
 
-	local reaper_task = async.runner(function(boundary_time)
+	module:daily("Remove expired files", function(_, boundary_time)
 		local prune_done = prune_start();
 		local iter, total = assert(uploads:find(nil, {["end"] = boundary_time; total = true}));
 
@@ -468,8 +468,10 @@
 		end
 
 		module:log("info", "Pruning expired files uploaded earlier than %s", dt.datetime(boundary_time));
-		if total_storage_limit then
+		if total_storage_usage then
 			module:log("debug", "Global quota %s / %s", B(total_storage_usage), B(total_storage_limit));
+		elseif total_storage_limit then
+			module:log("debug", "Global quota %s / %s", "not yet calculated", B(total_storage_limit));
 		end
 
 		local obsolete_uploads = array();
@@ -533,19 +535,12 @@
 
 		prune_done();
 	end);
-
-	module:add_timer(5, function ()
-		reaper_task:run(os.time()-expiry);
-		return 60*60;
-	end);
 end
 
 if total_storage_limit then
-	local async = require "util.async";
-
 	local summary_start = module:measure("summary", "times");
 
-	local summarizer_task = async.runner(function()
+	module:daily("Global quota check", function()
 		local summary_done = summary_start();
 		local iter = assert(uploads:find(nil));
 
@@ -561,10 +556,6 @@
 		summary_done();
 	end);
 
-	module:add_timer(1, function()
-		summarizer_task:run(true);
-		return 11 * 60 * 60;
-	end);
 end
 
 -- Reachable from the console