提交 0c5338a4 authored 作者: blu's avatar blu

feature: online update

上级 fd1202d8
...@@ -964,8 +964,13 @@ public: ...@@ -964,8 +964,13 @@ public:
spdlog::error("evslicer {} thEventHandler event ({}, {}) = ({}, {}) not in range: ({}, {}), ({}, {})", this->selfId, tss, tse, this->videoFileTs2Name(tss), this->videoFileTs2Name(tse), first, end, this->videoFileTs2Name(first), this->videoFileTs2Name(end)); spdlog::error("evslicer {} thEventHandler event ({}, {}) = ({}, {}) not in range: ({}, {}), ({}, {})", this->selfId, tss, tse, this->videoFileTs2Name(tss), this->videoFileTs2Name(tse), first, end, this->videoFileTs2Name(first), this->videoFileTs2Name(end));
} }
else { else {
vector<tuple<string, string> > params= {{"startTime", to_string(tss)},{"endTime", to_string(tse)},{"cameraId", ipcSn}, {"headOffset", to_string(offsetS)},{"tailOffset", to_string(offsetE)}}; json params;
vector<string> fileNames; params["startTime"] = to_string(tss);
params["endTime"] = to_string(tse);
params["cameraId"] = ipcSn;
params["headOffset"] = to_string(offsetS);
params["tailOffset"] = to_string(offsetE);
json fileNames;
string sf; string sf;
for(auto &i: v) { for(auto &i: v) {
string fname = this->urlOut + "/" + i + ".mp4"; string fname = this->urlOut + "/" + i + ".mp4";
...@@ -975,16 +980,20 @@ public: ...@@ -975,16 +980,20 @@ 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);
string strResp; string strResp;
ret = netutils::postFiles(std::move(this->videoFileServerApi), std::move(params), std::move(fileNames), strResp); ret = netutils::postFiles(this->videoFileServerApi, params, fileNames, strResp);
if( ret != 0 ) { if( ret != 0 ) {
spdlog::info("evslicer {} failed uploaded ({}, {}). local({}, {}). resp: {} files:\n{}", selfId, tss, tse, first, end, strResp, sf); spdlog::info("evslicer {} failed uploaded ({}, {}). local({}, {}). resp: {} files:\n{}", selfId, tss, tse, first, end, strResp, sf);
if(ret > 0) { if(ret > 0) {
if(jEvt.count("cnt") == 0) { if(jEvt.count("cnt") == 0) {
jEvt["cnt"] = ret; jEvt["cnt"] = ret;
}else{ }
if(jEvt["cnt"].get<int>() <= 0) { if(jEvt["cnt"].get<int>() <= 0) {
spdlog::error("evslicer {} failed to upload videos over N times, abort retrying: {}", this->selfId, evt); spdlog::error("evslicer {} failed to upload videos over N times, abort retrying: {}", selfId, evt);
// move to failed folder
system(string("mkdir -p /var/data/evsuits/failed_events/").c_str());
}else{ }else{
spdlog::info("evslicer {} retrying upload", selfId);
jEvt["cnt"] = jEvt["cnt"].get<int>() - 1; jEvt["cnt"] = jEvt["cnt"].get<int>() - 1;
lock_guard<mutex> lock(this->mutEvent); lock_guard<mutex> lock(this->mutEvent);
this->eventQueue.push(jEvt.dump()); this->eventQueue.push(jEvt.dump());
...@@ -995,7 +1004,6 @@ public: ...@@ -995,7 +1004,6 @@ public:
} }
} }
} }
}
else { else {
spdlog::info("evslicer {} upload ({}, {}). 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){ if(ret > 0){
...@@ -1006,7 +1014,7 @@ public: ...@@ -1006,7 +1014,7 @@ public:
if(resp.count("code") != 0 && resp["code"] != 0) { if(resp.count("code") != 0 && resp["code"] != 0) {
if(resp["code"] == 4|| resp["code"] == 7) { if(resp["code"] == 4|| resp["code"] == 7) {
if(jEvt.count("cnt") == 0) { if(jEvt.count("cnt") == 0) {
jEvt["cnt"] = 10; jEvt["cnt"] = 2;
}else{ }else{
if(jEvt["cnt"].get<int>() <= 0) { if(jEvt["cnt"].get<int>() <= 0) {
spdlog::error("evslicer {} failed to upload videos over N times, abort retrying: {}", this->selfId, evt); spdlog::error("evslicer {} failed to upload videos over N times, abort retrying: {}", this->selfId, evt);
......
...@@ -17,7 +17,7 @@ static size_t WriteCallback(char *contents, size_t size, size_t nmemb, void *use ...@@ -17,7 +17,7 @@ static size_t WriteCallback(char *contents, size_t size, size_t nmemb, void *use
return size * nmemb; return size * nmemb;
} }
int postFiles(string &&url, vector<tuple<string, string> > &&params, vector<string> &&fileNames, string &response){ int postFiles(string &url, json &params, json &fileNames, string &response){
CURL *curl; CURL *curl;
CURLcode res; CURLcode res;
curl_mime *form = NULL; curl_mime *form = NULL;
...@@ -38,14 +38,14 @@ int postFiles(string &&url, vector<tuple<string, string> > &&params, vector<stri ...@@ -38,14 +38,14 @@ int postFiles(string &&url, vector<tuple<string, string> > &&params, vector<stri
for(auto &f: fileNames) { for(auto &f: fileNames) {
field = curl_mime_addpart(form); field = curl_mime_addpart(form);
curl_mime_name(field, "files[]"); curl_mime_name(field, "files[]");
curl_mime_filedata(field, f.c_str()); curl_mime_filedata(field, string(f).c_str());
spdlog::debug("curl file: {}", f); spdlog::debug("curl file: {}", string(f));
} }
string queryString; string queryString;
int cnt = 0; int cnt = 0;
for(auto &[k, v]: params) { for(auto &[k, v]: params.items()) {
queryString += (cnt == 0?string(""):string("&")) + k + "=" + v; queryString += (cnt == 0?string(""):string("&")) + string(k) + "=" + string(v);
cnt++; cnt++;
} }
...@@ -63,9 +63,10 @@ int postFiles(string &&url, vector<tuple<string, string> > &&params, vector<stri ...@@ -63,9 +63,10 @@ int postFiles(string &&url, vector<tuple<string, string> > &&params, vector<stri
res = curl_easy_perform(curl); res = curl_easy_perform(curl);
/* Check for errors */ /* Check for errors */
if(res != CURLE_OK){ if(res != CURLE_OK){
spdlog::error("failed to upload files: {}", curl_easy_strerror(res)); spdlog::error("failed to upload files: {} - {}", res, curl_easy_strerror(res));
switch(res){ switch(res){
case CURLE_READ_ERROR: case CURLE_READ_ERROR:
case CURLE_RECV_ERROR:
case CURLE_UPLOAD_FAILED: case CURLE_UPLOAD_FAILED:
case CURLE_OPERATION_TIMEDOUT: case CURLE_OPERATION_TIMEDOUT:
case CURLE_SEND_ERROR: case CURLE_SEND_ERROR:
......
...@@ -3,13 +3,13 @@ ...@@ -3,13 +3,13 @@
#include <string> #include <string>
#include <curl/curl.h> #include <curl/curl.h>
#include <tuple>
#include <vector>
#include "inc/spdlog/spdlog.h" #include "inc/spdlog/spdlog.h"
#include "inc/json.hpp"
namespace netutils{ namespace netutils{
using namespace std; using namespace std;
int postFiles(string &&url, vector<tuple<string, string> > &&params, vector<string> &&fileNames, string &resp); using namespace nlohmann;
int postFiles(string &url, json &params, json &fileNames, string &resp);
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论