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

bugfix: resched event upload task

上级 2ad3eed7
...@@ -977,12 +977,38 @@ public: ...@@ -977,12 +977,38 @@ public:
spdlog::info("evslicer {} file upload range:({},{}) = ({}, {}), url: {}", selfId, tss, tse, this->videoFileTs2Name(tss), this->videoFileTs2Name(tse), this->videoFileServerApi); spdlog::info("evslicer {} file upload range:({},{}) = ({}, {}), url: {}", selfId, tss, tse, this->videoFileTs2Name(tss), this->videoFileTs2Name(tse), this->videoFileServerApi);
// TODO: check result and reschedule it // TODO: check result and reschedule it
if(netutils::postFiles(std::move(this->videoFileServerApi), std::move(params), std::move(fileNames)) != 0) { 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); spdlog::error("evslicer {} failed to upload files:\n{}", selfId, sf);
} }
else { else {
spdlog::info("evslicer {} successfully uploaded ({}, {}). local({}, {}). resp: {} files:\n{}", selfId, tss, tse, first, end, strResp, sf);
spdlog::info("evslicer {} successfully uploaded ({}, {}). local({}, {}) files:\n{}", selfId, tss, tse, first, end, sf); try{
auto resp = json::parse(strResp);
//TODO: open this swith when video server has implemented this functionality
if(false){
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());
}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();
}
}
}
}
}catch(exception &e) {
spdlog::error("evslicer {} {}:{} exception: {}", this->selfId, __FILE__, __LINE__, e.what());
}
} }
} }
} }
......
#include "postfile.h" #include "postfile.h"
namespace netutils{ namespace netutils{
// private
static void libcurlInit(){ static void libcurlInit(){
static bool inited = false; static bool inited = false;
if(inited == false) { if(inited == false) {
...@@ -10,7 +10,14 @@ static void libcurlInit(){ ...@@ -10,7 +10,14 @@ static void libcurlInit(){
} }
} }
int postFiles(string &&url, vector<tuple<string, string> > &&params, vector<string> &&fileNames){ // private
static size_t WriteCallback(char *contents, size_t size, size_t nmemb, void *userp)
{
((std::string*)userp)->append((char*)contents, size * nmemb);
return size * nmemb;
}
int postFiles(string &&url, vector<tuple<string, string> > &&params, vector<string> &&fileNames, string &response){
CURL *curl; CURL *curl;
CURLcode res; CURLcode res;
curl_mime *form = NULL; curl_mime *form = NULL;
...@@ -49,6 +56,8 @@ int postFiles(string &&url, vector<tuple<string, string> > &&params, vector<stri ...@@ -49,6 +56,8 @@ int postFiles(string &&url, vector<tuple<string, string> > &&params, vector<stri
curl_easy_setopt(curl, CURLOPT_URL, _url.c_str()); curl_easy_setopt(curl, CURLOPT_URL, _url.c_str());
//curl_easy_setopt(curl, CURLOPT_POSTFIELDS, queryString.c_str()); //curl_easy_setopt(curl, CURLOPT_POSTFIELDS, queryString.c_str());
curl_easy_setopt(curl, CURLOPT_MIMEPOST, form); curl_easy_setopt(curl, CURLOPT_MIMEPOST, form);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
/* Perform the request, res will get the return code */ /* Perform the request, res will get the return code */
res = curl_easy_perform(curl); res = curl_easy_perform(curl);
/* Check for errors */ /* Check for errors */
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
namespace netutils{ namespace netutils{
using namespace std; using namespace std;
int postFiles(string &&url, vector<tuple<string, string> > &&params, vector<string> &&fileNames); int postFiles(string &&url, vector<tuple<string, string> > &&params, vector<string> &&fileNames, string &resp);
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论