Skip to content

Commit

Permalink
录像文件自动整理支持
Browse files Browse the repository at this point in the history
  • Loading branch information
huahua132 committed Dec 5, 2024
1 parent 36eff07 commit 2b83d67
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 8 deletions.
16 changes: 15 additions & 1 deletion examples/AB_question/load_mods.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,32 @@ return {
B_m = {
launch_seq = 2,
launch_num = 4,
is_record_on = 1, --开启录像

--自动定时热更 skynet-fly.time_extend.time_point.lua 的配置项
auto_reload = {
type = 1, --每分钟
sec = 30, --第30秒
},

--录像文件自动整理
--需要启动logrotate_m
record_backup = {
max_age = 3, --最大保留天数
max_backups = 8,--最大保留文件数
point_type = 1, --每分钟整理一次
sec = 20, --第20秒整理
},

mod_args = {
{instance_name = "test_one"},
{instance_name = "test_one"},
{instance_name = "test_two"},
{instance_name = "test_two"},
}
}
},
logrotate_m = {
launch_seq = 3,
launch_num = 1,
}
}
21 changes: 20 additions & 1 deletion examples/record/load_mods.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,24 @@ return {
launch_seq = 3,
launch_num = 1,
is_record_on = 1, --录像
}

--自动定时热更 skynet-fly.time_extend.time_point.lua 的配置项
auto_reload = {
type = 1, --每分钟
sec = 30, --第30秒
},

--录像文件自动整理
--需要启动logrotate_m
record_backup = {
max_age = 3, --最大保留天数
max_backups = 8,--最大保留文件数
point_type = 1, --每分钟整理一次
sec = 20, --第20秒整理
},
},
logrotate_m = {
launch_seq = 4,
launch_num = 1,
}
}
3 changes: 2 additions & 1 deletion service/contriner_mgr.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ local function launch_new_module(module_name, config)
local launch_num = config.launch_num
local is_record_on = config.is_record_on --是否写录像
local auto_reload = config.auto_reload --自动热更机制
local record_backup = config.record_backup --录像文件整理
local mod_args = config.mod_args or {}
local default_arg = config.default_arg or {}

Expand All @@ -81,7 +82,7 @@ local function launch_new_module(module_name, config)
local server_id = skynet.newservice('hot_container',module_name,i,cur_date,cur_time,version,is_record_on)
local args = mod_args[i] or default_arg

local isok,ret = pcall(skynet_call, server_id, 'lua', 'start', args, auto_reload)
local isok,ret = pcall(skynet_call, server_id, 'lua', 'start', args, auto_reload, record_backup)
if not isok or not ret then
log.fatal("launch_new_module err ",module_name,args)
is_ok = false
Expand Down
41 changes: 36 additions & 5 deletions service/hot_container.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ assert(MODULE_NAME)
local new_loaded = _loaded

if IS_RECORD_ON == 1 then
skynet.start_record(ARGV, MODULE_NAME .. '-' .. INDEX .. '-' .. VERSION .. '-' .. os.date('%Y%m%d-%H%M%S', LAUNCH_TIME))
skynet.start_record(ARGV, MODULE_NAME .. '-' .. VERSION .. '-' .. INDEX .. '-' .. os.date('%Y%m%d-%H%M%S', LAUNCH_TIME))
end

local CMD = {}
Expand Down Expand Up @@ -167,7 +167,7 @@ local function check_exit()
end
end

function CMD.start(cfg, auto_reload)
function CMD.start(cfg, auto_reload, record_backup)
if g_breakpoint_debug_host and g_breakpoint_debug_port then
log.warn_fmt("start breakpoint module_name[%s] index[%s] host[%s] port[%s]", MODULE_NAME, INDEX, g_breakpoint_debug_host, g_breakpoint_debug_port)
require("skynet-fly.LuaPanda").start(g_breakpoint_debug_host, g_breakpoint_debug_port);
Expand All @@ -187,16 +187,15 @@ function CMD.start(cfg, auto_reload)
for _,func in ipairs(g_start_after_cb) do
skynet.fork(func)
end
contriner_client:open_ready()
SERVER_STATE = SERVER_STATE_TYPE.starting

--自动热更处理
if auto_reload and INDEX == 1 then
local timer_point = require "skynet-fly.time_extend.timer_point"
g_time_point_obj = timer_point:new(auto_reload.type)

local function set_time_point_opt(opt)
if auto_reload[opt] then
local set_func = assert(g_time_point_obj['set_' .. opt], "opt func not exists: " .. opt)
local set_func = assert(timer_point['set_' .. opt], "opt func not exists: " .. opt)
g_time_point_obj = set_func(g_time_point_obj, auto_reload[opt])
end
end
Expand All @@ -212,6 +211,38 @@ function CMD.start(cfg, auto_reload)
skynet.send('.contriner_mgr','lua','load_modules', skynet.self(), MODULE_NAME)
end)
end

--录像保留文件整理
if record_backup and INDEX == 1 and IS_RECORD_ON == 1 then
local logrotate = require "skynet-fly.logrotate"
skynet.fork(function()
local rotate_obj = logrotate:new()
:set_file_path(skynet.getenv('recordpath'))
local function set_rotate_opt(opt)
if record_backup[opt] then
local set_func = assert(logrotate['set_' .. opt], "opt func not exists: " .. opt)
rotate_obj = set_func(rotate_obj, record_backup[opt])
end
end
set_rotate_opt('max_age')
set_rotate_opt('max_backups')

set_rotate_opt('point_type')
set_rotate_opt('month')
set_rotate_opt('day')
set_rotate_opt('hour')
set_rotate_opt('min')
set_rotate_opt('sec')
set_rotate_opt('wday')
set_rotate_opt('yday')

rotate_obj:set_back_pattern(MODULE_NAME) --设置匹配文件名
rotate_obj:builder()
end)
end

contriner_client:open_ready()
SERVER_STATE = SERVER_STATE_TYPE.starting
else
SERVER_STATE = SERVER_STATE_TYPE.start_failed
end
Expand Down

0 comments on commit 2b83d67

Please sign in to comment.