--[[ Descripttion:配置管理 version: Author: Neo,Huang Date: 2022-07-04 11:24:54 LastEditors: Neo,Huang LastEditTime: 2022-07-04 16:49:25 --]] local skynet = require "skynet" local sharetable = require "skynet.sharetable" local lfsUtil = require "utils.lfsUtil" local baseService = require "baseService" local pathConfig = skynet.getenv("config_path") local MAP_FILE_MOD_TIME = {} -- 文件修改时间 local command = {} local SLEEPTIME = 60 * 100 local function l_collect_garbage() while true do skynet.sleep(SLEEPTIME) collectgarbage "collect" end end local function l_get_file_path_name(file) return pathConfig .. file end -- 获取配置文件更新时间 local function l_get_files_time(fileList) local files = fileList or lfsUtil:get_path_files(pathConfig) local mapFileTime = {} for _, file in pairs(files) do mapFileTime[file] = lfsUtil:get_file_modification(l_get_file_path_name(file)) end return mapFileTime end -- 更新配置文件 local function l_get_update_file_list() local updateFileList = {} local mapFileTime = l_get_files_time() for file, time in pairs(mapFileTime) do if time ~= MAP_FILE_MOD_TIME[file] then sharetable.loadfile(l_get_file_path_name(file)) table.insert(updateFileList, l_get_file_path_name(file)) MAP_FILE_MOD_TIME[file] = time end end return updateFileList end local function l_init() local files = lfsUtil:get_path_files(pathConfig) for _, file in pairs(files) do sharetable.loadfile(l_get_file_path_name(file)) end MAP_FILE_MOD_TIME = l_get_files_time(files) end -- 获取更新文件 function command.get_update_files() local syscmd = string.format("cd %s", pathConfig) os.execute(syscmd) os.execute("git pull") local updateList = l_get_update_file_list() if #updateList <= 0 then return end return updateList end function command.onStart() l_init() skynet.fork(l_collect_garbage) end baseService.start(command, ".config", true)