Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
ZLMediaKit
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
张翔宇
ZLMediaKit
Commits
01350c81
Unverified
Commit
01350c81
authored
Jun 15, 2022
by
Leon
Committed by
Gitee
Jun 15, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update server/WebHook.cpp.
配置文件HOOK添加retry ,设置hook通知失败重试的次数。默认为0,不重试,
parent
dfec2d76
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
21 行增加
和
3 行删除
+21
-3
server/WebHook.cpp
+21
-3
没有找到文件。
server/WebHook.cpp
查看文件 @
01350c81
/*
/*
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
*
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
...
...
@@ -47,6 +47,7 @@ const string kOnServerStarted = HOOK_FIELD"on_server_started";
const
string
kOnServerKeepalive
=
HOOK_FIELD
"on_server_keepalive"
;
const
string
kAdminParams
=
HOOK_FIELD
"admin_params"
;
const
string
kAliveInterval
=
HOOK_FIELD
"alive_interval"
;
const
string
kRetry
=
HOOK_FIELD
"retry"
;
onceToken
token
([](){
mINI
::
Instance
()[
kEnable
]
=
false
;
...
...
@@ -68,6 +69,8 @@ onceToken token([](){
mINI
::
Instance
()[
kOnServerKeepalive
]
=
""
;
mINI
::
Instance
()[
kAdminParams
]
=
"secret=035c73f7-bb6b-4889-a715-d9eb2d1925cc"
;
mINI
::
Instance
()[
kAliveInterval
]
=
30.0
;
mINI
::
Instance
()[
kRetry
]
=
0
;
},
nullptr
);
}
//namespace Hook
...
...
@@ -85,6 +88,8 @@ static onceToken token([]() {
}
//namespace Cluster
void
do_http_process
(
HttpRequester
::
Ptr
&
requester
,
const
string
&
url
,
const
string
&
bodyStr
,
const
function
<
void
(
const
Value
&
,
const
string
&
)
>
&
func
,
int
retry
,
float
timeout_sec
);
static
void
parse_http_response
(
const
SockException
&
ex
,
const
Parser
&
res
,
const
function
<
void
(
const
Value
&
,
const
string
&
)
>
&
fun
){
if
(
ex
)
{
...
...
@@ -150,6 +155,7 @@ string getVhost(const HttpArgs &value) {
void
do_http_hook
(
const
string
&
url
,
const
ArgsType
&
body
,
const
function
<
void
(
const
Value
&
,
const
string
&
)
>
&
func
){
GET_CONFIG
(
string
,
mediaServerId
,
General
::
kMediaServerId
);
GET_CONFIG
(
float
,
hook_timeoutSec
,
Hook
::
kTimeoutSec
);
GET_CONFIG
(
int
,
hook_retry
,
Hook
::
kRetry
);
const_cast
<
ArgsType
&>
(
body
)[
"mediaServerId"
]
=
mediaServerId
;
HttpRequester
::
Ptr
requester
(
new
HttpRequester
);
...
...
@@ -161,8 +167,14 @@ void do_http_hook(const string &url,const ArgsType &body,const function<void(con
if
(
!
vhost
.
empty
())
{
requester
->
addHeader
(
"X-VHOST"
,
vhost
);
}
do_http_process
(
requester
,
url
,
bodyStr
,
func
,
hook_retry
,
hook_timeoutSec
);
}
void
do_http_process
(
HttpRequester
::
Ptr
&
requester
,
const
string
&
url
,
const
string
&
bodyStr
,
const
function
<
void
(
const
Value
&
,
const
string
&
)
>
&
func
,
int
retry
,
float
timeout_sec
){
std
::
shared_ptr
<
Ticker
>
pTicker
(
new
Ticker
);
requester
->
startRequester
(
url
,
[
url
,
func
,
bodyStr
,
requester
,
pTicker
](
const
SockException
&
ex
,
requester
->
startRequester
(
url
,
[
url
,
func
,
bodyStr
,
requester
,
pTicker
,
retry
,
timeout_sec
](
const
SockException
&
ex
,
const
Parser
&
res
)
mutable
{
onceToken
token
(
nullptr
,
[
&
]()
mutable
{
requester
.
reset
();
...
...
@@ -176,8 +188,14 @@ void do_http_hook(const string &url,const ArgsType &body,const function<void(con
}
else
if
(
pTicker
->
elapsedTime
()
>
500
)
{
DebugL
<<
"hook "
<<
url
<<
" "
<<
pTicker
->
elapsedTime
()
<<
"ms,success:"
<<
bodyStr
;
}
//尾部递归重试
if
(
!
err
.
empty
()
&&
retry
--
>
0
)
{
//WarnL << "----------------hook retry------------------ " << retry ;
HttpRequester
::
Ptr
requester
(
new
HttpRequester
);
do_http_process
(
requester
,
url
,
bodyStr
,
func
,
retry
,
timeout_sec
);
}
});
},
hook_timeoutS
ec
);
},
timeout_s
ec
);
}
static
ArgsType
make_json
(
const
MediaInfo
&
args
){
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论