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

feature: online update

上级 fd1202d8
......@@ -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));
}
else {
vector<tuple<string, string> > params= {{"startTime", to_string(tss)},{"endTime", to_string(tse)},{"cameraId", ipcSn}, {"headOffset", to_string(offsetS)},{"tailOffset", to_string(offsetE)}};
vector<string> fileNames;
json params;
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;
for(auto &i: v) {
string fname = this->urlOut + "/" + i + ".mp4";
......@@ -975,25 +980,28 @@ public:
spdlog::info("evslicer {} file upload range:({},{}) = ({}, {}), url: {}", selfId, tss, tse, this->videoFileTs2Name(tss), this->videoFileTs2Name(tse), this->videoFileServerApi);
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 ) {
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;
}
if(jEvt["cnt"].get<int>() <= 0) {
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{
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();
spdlog::info("evslicer {} retrying upload", selfId);
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 {
......@@ -1006,7 +1014,7 @@ public:
if(resp.count("code") != 0 && resp["code"] != 0) {
if(resp["code"] == 4|| resp["code"] == 7) {
if(jEvt.count("cnt") == 0) {
jEvt["cnt"] = 10;
jEvt["cnt"] = 2;
}else{
if(jEvt["cnt"].get<int>() <= 0) {
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
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;
CURLcode res;
curl_mime *form = NULL;
......@@ -38,14 +38,14 @@ int postFiles(string &&url, vector<tuple<string, string> > &&params, vector<stri
for(auto &f: fileNames) {
field = curl_mime_addpart(form);
curl_mime_name(field, "files[]");
curl_mime_filedata(field, f.c_str());
spdlog::debug("curl file: {}", f);
curl_mime_filedata(field, string(f).c_str());
spdlog::debug("curl file: {}", string(f));
}
string queryString;
int cnt = 0;
for(auto &[k, v]: params) {
queryString += (cnt == 0?string(""):string("&")) + k + "=" + v;
for(auto &[k, v]: params.items()) {
queryString += (cnt == 0?string(""):string("&")) + string(k) + "=" + string(v);
cnt++;
}
......@@ -63,9 +63,10 @@ int postFiles(string &&url, vector<tuple<string, string> > &&params, vector<stri
res = curl_easy_perform(curl);
/* Check for errors */
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){
case CURLE_READ_ERROR:
case CURLE_RECV_ERROR:
case CURLE_UPLOAD_FAILED:
case CURLE_OPERATION_TIMEDOUT:
case CURLE_SEND_ERROR:
......
......@@ -3,13 +3,13 @@
#include <string>
#include <curl/curl.h>
#include <tuple>
#include <vector>
#include "inc/spdlog/spdlog.h"
#include "inc/json.hpp"
namespace netutils{
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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论