|
|
@ -34,6 +34,10 @@ end |
|
|
|
function _M.getInstance(self) |
|
|
|
function _M.getInstance(self) |
|
|
|
if rawget(self, "instance") == nil then |
|
|
|
if rawget(self, "instance") == nil then |
|
|
|
rawset(self, "instance", self:new()) |
|
|
|
rawset(self, "instance", self:new()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if 0 == ngx.worker.id() then |
|
|
|
|
|
|
|
self:cron() |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
assert(self.instance ~= nil) |
|
|
|
assert(self.instance ~= nil) |
|
|
|
return self.instance |
|
|
|
return self.instance |
|
|
@ -56,6 +60,25 @@ function _M.initDB(self) |
|
|
|
return db |
|
|
|
return db |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- 后台任务 |
|
|
|
|
|
|
|
function _M.cron(self) |
|
|
|
|
|
|
|
local timer_every_get_data = function (premature) |
|
|
|
|
|
|
|
self.clean_log() |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
ngx.timer.every(10, timer_every_get_data) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _M.clean_log(self) |
|
|
|
|
|
|
|
local db = self:initDB() |
|
|
|
|
|
|
|
local now_date = os.date("*t") |
|
|
|
|
|
|
|
local save_day = 90 |
|
|
|
|
|
|
|
local save_date_timestamp = os.time{year=now_date.year, |
|
|
|
|
|
|
|
month=now_date.month, day=now_date.day-save_day, hour=0} |
|
|
|
|
|
|
|
-- delete expire data |
|
|
|
|
|
|
|
db:exec("DELETE FROM web_logs WHERE time<"..tostring(save_date_timestamp)) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
function _M.log(self, args, rule_name, reason) |
|
|
|
function _M.log(self, args, rule_name, reason) |
|
|
|
local db = self:initDB() |
|
|
|
local db = self:initDB() |
|
|
|
|
|
|
|
|
|
|
|