mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-26 20:47:08 +08:00
update server/WebHook.cpp.
配置文件HOOK添加retry ,设置hook通知失败重试的次数。默认为0,不重试,
This commit is contained in:
parent
dfec2d76e0
commit
01350c810e
@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
* 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 kOnServerKeepalive = HOOK_FIELD"on_server_keepalive";
|
||||||
const string kAdminParams = HOOK_FIELD"admin_params";
|
const string kAdminParams = HOOK_FIELD"admin_params";
|
||||||
const string kAliveInterval = HOOK_FIELD"alive_interval";
|
const string kAliveInterval = HOOK_FIELD"alive_interval";
|
||||||
|
const string kRetry = HOOK_FIELD"retry";
|
||||||
|
|
||||||
onceToken token([](){
|
onceToken token([](){
|
||||||
mINI::Instance()[kEnable] = false;
|
mINI::Instance()[kEnable] = false;
|
||||||
@ -68,6 +69,8 @@ onceToken token([](){
|
|||||||
mINI::Instance()[kOnServerKeepalive] = "";
|
mINI::Instance()[kOnServerKeepalive] = "";
|
||||||
mINI::Instance()[kAdminParams] = "secret=035c73f7-bb6b-4889-a715-d9eb2d1925cc";
|
mINI::Instance()[kAdminParams] = "secret=035c73f7-bb6b-4889-a715-d9eb2d1925cc";
|
||||||
mINI::Instance()[kAliveInterval] = 30.0;
|
mINI::Instance()[kAliveInterval] = 30.0;
|
||||||
|
mINI::Instance()[kRetry] = 0;
|
||||||
|
|
||||||
},nullptr);
|
},nullptr);
|
||||||
}//namespace Hook
|
}//namespace Hook
|
||||||
|
|
||||||
@ -85,6 +88,8 @@ static onceToken token([]() {
|
|||||||
|
|
||||||
}//namespace Cluster
|
}//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,
|
static void parse_http_response(const SockException &ex, const Parser &res,
|
||||||
const function<void(const Value &,const string &)> &fun){
|
const function<void(const Value &,const string &)> &fun){
|
||||||
if (ex) {
|
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){
|
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(string, mediaServerId, General::kMediaServerId);
|
||||||
GET_CONFIG(float, hook_timeoutSec, Hook::kTimeoutSec);
|
GET_CONFIG(float, hook_timeoutSec, Hook::kTimeoutSec);
|
||||||
|
GET_CONFIG(int, hook_retry, Hook::kRetry);
|
||||||
|
|
||||||
const_cast<ArgsType &>(body)["mediaServerId"] = mediaServerId;
|
const_cast<ArgsType &>(body)["mediaServerId"] = mediaServerId;
|
||||||
HttpRequester::Ptr requester(new HttpRequester);
|
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()) {
|
if (!vhost.empty()) {
|
||||||
requester->addHeader("X-VHOST", vhost);
|
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);
|
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{
|
const Parser &res) mutable{
|
||||||
onceToken token(nullptr, [&]() mutable{
|
onceToken token(nullptr, [&]() mutable{
|
||||||
requester.reset();
|
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) {
|
} else if (pTicker->elapsedTime() > 500) {
|
||||||
DebugL << "hook " << url << " " << pTicker->elapsedTime() << "ms,success:" << bodyStr;
|
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_timeoutSec);
|
}, timeout_sec);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ArgsType make_json(const MediaInfo &args){
|
static ArgsType make_json(const MediaInfo &args){
|
||||||
|
Loading…
Reference in New Issue
Block a user