提交 fd1202d8 authored 作者: blu's avatar blu

feature: online update

上级 63adf2ae
......@@ -974,26 +974,44 @@ public:
}
spdlog::info("evslicer {} file upload range:({},{}) = ({}, {}), url: {}", selfId, tss, tse, this->videoFileTs2Name(tss), this->videoFileTs2Name(tse), this->videoFileServerApi);
// TODO: check result and reschedule it
string strResp;
if(netutils::postFiles(std::move(this->videoFileServerApi), std::move(params), std::move(fileNames), strResp) != 0) {
spdlog::error("evslicer {} failed to upload files:\n{}", selfId, sf);
ret = netutils::postFiles(std::move(this->videoFileServerApi), std::move(params), std::move(fileNames), strResp);
if( ret != 0 ) {
spdlog::info("evslicer {} failed uploaded ({}, {}). local({}, {}). resp: {} files:\n{}", selfId, tss, tse, first, end, strResp, sf);
if(ret > 0) {
if(jEvt.count("cnt") == 0) {
jEvt["cnt"] = ret;
}else{
if(jEvt["cnt"].get<int>() <= 0) {
spdlog::error("evslicer {} failed to upload videos over N times, abort retrying: {}", this->selfId, evt);
}else{
jEvt["cnt"] = jEvt["cnt"].get<int>() - 1;
lock_guard<mutex> lock(this->mutEvent);
this->eventQueue.push(jEvt.dump());
if(eventQueue.size() > MAX_EVENT_QUEUE_SIZE) {
eventQueue.pop();
}
cvEvent.notify_one();
}
}
}
}
else {
spdlog::info("evslicer {} successfully uploaded ({}, {}). local({}, {}). resp: {} files:\n{}", selfId, tss, tse, first, end, strResp, sf);
spdlog::info("evslicer {} upload ({}, {}). local({}, {}). resp: {} files:\n{}", selfId, tss, tse, first, end, strResp, sf);
if(ret > 0){
try{
auto resp = json::parse(strResp);
//TODO: open this swith when video server has implemented this functionality
if(false){
if(true){
if(resp.count("code") != 0 && resp["code"] != 0) {
if(resp["code"] == 4|| resp["code"] == 7) {
if(jEvt.count("cnt") == 0) {
jEvt["cnt"] = 0;
}
if(jEvt["cnt"].get<int>() > 10) {
spdlog::error("evslicer {} failed to upload videos over 10 times, abort retrying: {}", this->selfId, jEvt.dump());
jEvt["cnt"] = 10;
}else{
jEvt["cnt"] = jEvt["cnt"].get<int>() + 1;
if(jEvt["cnt"].get<int>() <= 0) {
spdlog::error("evslicer {} failed to upload videos over N times, abort retrying: {}", this->selfId, evt);
}else{
jEvt["cnt"] = jEvt["cnt"].get<int>() - 1;
lock_guard<mutex> lock(this->mutEvent);
this->eventQueue.push(jEvt.dump());
if(eventQueue.size() > MAX_EVENT_QUEUE_SIZE) {
......@@ -1001,8 +1019,12 @@ public:
}
cvEvent.notify_one();
}
}
}else if(resp["code"] == 6) {
// TODO: cloud storage issue. need stratigy policy
spdlog::warn("evslicer {} TODO: handle cloud storage", this->selfId);
}else{
spdlog::error("evslicer {} failed to upload videos. abort retry.", this->selfId);
}
}
}
......@@ -1012,6 +1034,7 @@ public:
}
}
}
}
else {
spdlog::error("evslicer {} unkown event :{}", this->selfId, evt);
}
......
......@@ -23,6 +23,7 @@ int postFiles(string &&url, vector<tuple<string, string> > &&params, vector<stri
curl_mime *form = NULL;
curl_mimepart *field = NULL;
struct curl_slist *headerlist = NULL;
int ret = 0;
libcurlInit();
curl = curl_easy_init();
......@@ -63,7 +64,27 @@ int postFiles(string &&url, vector<tuple<string, string> > &&params, vector<stri
/* Check for errors */
if(res != CURLE_OK){
spdlog::error("failed to upload files: {}", curl_easy_strerror(res));
return -1;
switch(res){
case CURLE_READ_ERROR:
case CURLE_UPLOAD_FAILED:
case CURLE_OPERATION_TIMEDOUT:
case CURLE_SEND_ERROR:
case CURLE_AGAIN:
case CURLE_COULDNT_RESOLVE_PROXY:
case CURLE_COULDNT_RESOLVE_HOST:
case CURLE_COULDNT_CONNECT:
case CURLE_WEIRD_SERVER_REPLY:
case CURLE_REMOTE_ACCESS_DENIED:
case CURLE_FAILED_INIT:
//case CURLE_OUT_OF_MEMORY:
case CURLE_HTTP_POST_ERROR:
case CURLE_FILE_COULDNT_READ_FILE:{
ret = 2;
break;
}
default:
ret = -1;
}
}
/* always cleanup */
......@@ -73,7 +94,7 @@ int postFiles(string &&url, vector<tuple<string, string> > &&params, vector<stri
/* free slist */
curl_slist_free_all(headerlist);
return 0;
return ret;
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论