From 29144595a64cb33aa175fd98d63afd28871cd9fc Mon Sep 17 00:00:00 2001 From: midoks Date: Sun, 12 Feb 2023 00:22:39 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BD=91=E7=AB=99=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/webstats/index.py | 18 +++++++++--------- plugins/webstats/info.json | 2 +- plugins/webstats/lua/webstats_common.lua | 9 +++++++++ plugins/webstats/lua/webstats_log.lua | 2 +- plugins/webstats/lua/webstats_worker.lua | 3 ++- 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/plugins/webstats/index.py b/plugins/webstats/index.py index 73d60769f..7eca6be22 100755 --- a/plugins/webstats/index.py +++ b/plugins/webstats/index.py @@ -260,15 +260,15 @@ def initDreplace(): loadLuaFile(fl) root_worker_dir = mw.getServerDir() + '/web_conf/nginx/lua/init_worker_by_lua_file' - webstats_worker_dst_file = root_worker_dir + '/webstats_worker.lua' + dst_file = root_worker_dir + '/webstats_worker.lua' - if not os.path.exists(webstats_worker_src_file): + if not os.path.exists(dst_file): loadLuaFile('webstats_worker.lua') - webstats_worker_src_file = lua_dir = getServerDir() + "/lua/webstats_worker.lua" - content = mw.readFile(webstats_worker_src_file) - mw.writeFile(webstats_worker_dst_file, content) + src_file = getServerDir() + "/lua/webstats_worker.lua" + content = mw.readFile(src_file) + mw.writeFile(dst_file, content) mw.opLuaInitWorkerFile() - os.remove(webstats_worker_src_file) + os.remove(src_file) loadConfigFile() loadLuaSiteFile() @@ -302,9 +302,9 @@ def stop(): os.remove(path) root_worker_dir = mw.getServerDir() + '/web_conf/nginx/lua/init_worker_by_lua_file' - webstats_worker_dst_file = root_worker_dir + '/webstats_worker.lua' - if os.path.exists(webstats_worker_dst_file): - os.remove(webstats_worker_dst_file) + dst_file = root_worker_dir + '/webstats_worker.lua' + if os.path.exists(dst_file): + os.remove(dst_file) mw.opLuaInitWorkerFile() import tool_task diff --git a/plugins/webstats/info.json b/plugins/webstats/info.json index 978ec07d6..847247e62 100755 --- a/plugins/webstats/info.json +++ b/plugins/webstats/info.json @@ -4,7 +4,7 @@ "name": "webstats", "title": "网站统计", "shell": "install.sh", - "versions":["0.2.3"], + "versions":["0.2.4"], "tip": "soft", "install_pre_inspection":true, "checks": "server/webstats", diff --git a/plugins/webstats/lua/webstats_common.lua b/plugins/webstats/lua/webstats_common.lua index f86700296..479fbde34 100644 --- a/plugins/webstats/lua/webstats_common.lua +++ b/plugins/webstats/lua/webstats_common.lua @@ -36,6 +36,8 @@ function _M.new(self) params = nil, site_config = nil, config = nil, + cron_num = 0, + cron_num_limit = 4, } -- self.dbs = {} @@ -254,6 +256,13 @@ end -- 后台任务 function _M.cron(self) + self.cron_num = self.cron_num + 1 + if self.cron_num > self.cron_num_limit then + return + end + + -- self:D("PID:"..tostring(ngx.worker.id())..",cron_num:"..tostring(self.cron_num)) + local timer_every_get_data = function (premature) local llen, _ = ngx.shared.mw_total:llen(total_key) diff --git a/plugins/webstats/lua/webstats_log.lua b/plugins/webstats/lua/webstats_log.lua index c20a5383c..fc576a377 100644 --- a/plugins/webstats/lua/webstats_log.lua +++ b/plugins/webstats/lua/webstats_log.lua @@ -8,7 +8,7 @@ log_by_lua_block { package.path = cpath .. "?.lua;" .. package.path end - local ver = '0.2.3' + local ver = '0.2.4' local debug_mode = true local __C = require "webstats_common" diff --git a/plugins/webstats/lua/webstats_worker.lua b/plugins/webstats/lua/webstats_worker.lua index 08ff6f9bf..deca2b8a7 100644 --- a/plugins/webstats/lua/webstats_worker.lua +++ b/plugins/webstats/lua/webstats_worker.lua @@ -10,11 +10,12 @@ local __WS_C = require "webstats_common" local WS_C = __WS_C:getInstance() WS_C:cronPre() +WS_C:cron() + local webstats_cron_pre = function(premature) WS_C:cronPre() end if ngx.worker.id() == 0 then ngx.timer.every(60, webstats_cron_pre) - WS_C:cron() end \ No newline at end of file