Mercurial Hosting > luan
changeset 1188:9f5edbef3f55
remove old web log files
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 22 Feb 2018 23:21:06 -0700 |
parents | 83c8a5a47f70 |
children | 73d754b1889f |
files | src/luan/host/run.luan src/luan/modules/Thread.luan |
diffstat | 2 files changed, 33 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/luan/host/run.luan Thu Feb 22 18:38:45 2018 -0700 +++ b/src/luan/host/run.luan Thu Feb 22 23:21:06 2018 -0700 @@ -6,6 +6,8 @@ local Io = require "luan:Io.luan" local print = Io.print or error() local String = require "luan:String.luan" +local Time = require "luan:Time.luan" +local Thread = require "luan:Thread.luan" local Hosting = require "luan:host/Hosting.luan" local Logging = require "luan:logging/Logging.luan" local logger = Logging.logger "run" @@ -31,3 +33,20 @@ handler = SafeHandler.new(handler) local server = Server.ForAddress.new("127.0.0.1",8080,handler) server.start() + + + +local function remove_old_web_log_files() + local expired = Time.now() - Time.period{days=30} + local sites_dir = Io.schemes.file(Hosting.sites_dir) + for _, site in ipairs(sites_dir.children()) do + local web = site.child("site/private/local/logs/web") + for _, file in ipairs(web.children() or {}) do + if file.last_modified() < expired then + file.delete() + end + end + end +end + +Thread.schedule( Time.period{days=1}, true, Thread.safe(remove_old_web_log_files,logger) )
--- a/src/luan/modules/Thread.luan Thu Feb 22 18:38:45 2018 -0700 +++ b/src/luan/modules/Thread.luan Thu Feb 22 23:21:06 2018 -0700 @@ -3,6 +3,7 @@ local Luan = require "luan:Luan.luan" local error = Luan.error local set_metatable = Luan.set_metatable or error() +local try = Luan.try or error() local Thread = {} @@ -11,6 +12,19 @@ Thread.schedule = ThreadLuan.schedule Thread.sleep = ThreadLuan.sleep +function Thread.safe(fn,logger) + return function() + try { + function() + fn() + end + catch = function(e) + logger.error(e) + end + } + end +end + --[[ Thread.global = {} -- shared across threads local map = ThreadLuan.GlobalMap.new()