Comparison

plugins/mod_http_file_share.lua @ 11329:2a431d3ad8f1

mod_http_file_share: Insert pauses to avoid blocknig for long periods Similar to the mod_mam cleanup job
author Kim Alvefur <zash@zash.se>
date Wed, 27 Jan 2021 22:10:11 +0100
parent 11328:ceaa3cebf28b
child 11330:f2c9492e3d25
comparison
equal deleted inserted replaced
11328:ceaa3cebf28b 11329:2a431d3ad8f1
261 -- TODO HTTP DELETE to the external endpoint? 261 -- TODO HTTP DELETE to the external endpoint?
262 local array = require "util.array"; 262 local array = require "util.array";
263 local async = require "util.async"; 263 local async = require "util.async";
264 local ENOENT = require "util.pposix".ENOENT; 264 local ENOENT = require "util.pposix".ENOENT;
265 265
266 local function sleep(t)
267 local wait, done = async.waiter();
268 module:add_timer(t, done)
269 wait();
270 end
271
266 local reaper_task = async.runner(function(boundary_time) 272 local reaper_task = async.runner(function(boundary_time)
267 local iter, total = assert(uploads:find(nil, {["end"] = boundary_time; total = true})); 273 local iter, total = assert(uploads:find(nil, {["end"] = boundary_time; total = true}));
268 274
269 if total == 0 then 275 if total == 0 then
270 module:log("info", "No expired to prune"); 276 module:log("info", "No expired to prune");
278 for slot_id in iter do 284 for slot_id in iter do
279 i = i + 1; 285 i = i + 1;
280 obsolete_files:push(get_filename(slot_id)); 286 obsolete_files:push(get_filename(slot_id));
281 end 287 end
282 288
289 sleep(0.1);
283 local n = 0; 290 local n = 0;
284 obsolete_files:filter(function(filename) 291 obsolete_files:filter(function(filename)
285 n = n + 1; 292 n = n + 1;
293 if i % 100 == 0 then sleep(0.1); end
286 local deleted, err, errno = os.remove(filename); 294 local deleted, err, errno = os.remove(filename);
287 if deleted or errno == ENOENT then 295 if deleted or errno == ENOENT then
288 return false; 296 return false;
289 else 297 else
290 module:log("error", "Could not delete file %q: %s", filename, err); 298 module:log("error", "Could not delete file %q: %s", filename, err);