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

feature: report status

上级 e973400e
...@@ -690,7 +690,7 @@ private: ...@@ -690,7 +690,7 @@ private:
} }
} }
if(catId == EV_MSG_REPORT_CATID_AVMODOFFLINE || catId == EV_MSG_REPORT_CATID_AVWRITEPIPE || (modId.find("evpuller") != string::npos && catId == EV_MSG_REPORT_CATID_AVOPENINPUT)) { if(catId == EV_MSG_REPORT_CATID_AVFAILEDUPLOAD ||catId == EV_MSG_REPORT_CATID_AVMODOFFLINE || catId == EV_MSG_REPORT_CATID_AVWRITEPIPE || (modId.find("evpuller") != string::npos && catId == EV_MSG_REPORT_CATID_AVOPENINPUT)) {
ipcStatus["current"][modId] = true; ipcStatus["current"][modId] = true;
} }
} }
......
...@@ -53,7 +53,7 @@ private: ...@@ -53,7 +53,7 @@ private:
json slices; json slices;
condition_variable cvMsg; condition_variable cvMsg;
mutex mutMsg; mutex mutMsg;
bool gotFormat = false; bool gotFormat = false, bUploadFailed = false;
queue<string> eventQueue; queue<string> eventQueue;
condition_variable cvEvent; condition_variable cvEvent;
mutex mutEvent; mutex mutEvent;
...@@ -865,6 +865,24 @@ protected: ...@@ -865,6 +865,24 @@ protected:
return ret; return ret;
} }
void reportUploadFailure(string modId, bool fail, string reason){
string modifier = fail?"failed": "successfully";
string status = fail?"active":"recover";
string msg = fmt::format("evslicer {} {} upload videos: {}", selfId, modifier, reason);
json meta;
json data;
data["msg"] = msg;
data["modId"] = modId;
data["type"] = EV_MSG_META_TYPE_REPORT;
data["catId"] = EV_MSG_REPORT_CATID_AVFAILEDUPLOAD;
data["level"] = EV_MSG_META_VALUE_REPORT_LEVEL_FATAL;
data["time"] = chrono::duration_cast<chrono::seconds>(chrono::system_clock::now().time_since_epoch()).count();
data["status"] = "recover";
meta["type"] = EV_MSG_META_TYPE_REPORT;
meta["value"] = EV_MSG_META_VALUE_REPORT_LEVEL_FATAL;
z_send(pDaemon, "evcloudsvc", meta.dump(), data.dump());
}
public: public:
EvSlicer() EvSlicer()
{ {
...@@ -1040,14 +1058,18 @@ public: ...@@ -1040,14 +1058,18 @@ public:
string strResp; string strResp;
ret = netutils::postFiles(this->videoFileServerApi, params, 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); bUploadFailed = true;
spdlog::error("evslicer {} failed uploaded ({}, {}). local({}, {}). resp: {} files:\n{}", selfId, tss, tse, first, end, strResp, sf);
reportUploadFailure(selfId, true, strResp);
if(ret > 0) { if(ret > 0) {
if(jEvt.count("cnt") == 0) { if(jEvt.count("cnt") == 0) {
jEvt["cnt"] = ret; jEvt["cnt"] = ret;
} }
if(jEvt["cnt"].get<int>() <= 0) { if(jEvt["cnt"].get<int>() <= 0) {
spdlog::error("evslicer {} failed to upload videos over N times, abort retrying: {}", selfId, evt); // TODO: report message to cloud
string msg = fmt::format("evslicer {} failed to upload videos over N times: {}", selfId, strResp);
spdlog::error(msg);
// TODO: move to failed folder // TODO: move to failed folder
string dirDest = "/var/data/evsuits/failed_events/"; string dirDest = "/var/data/evsuits/failed_events/";
system((string("mkdir -p ") + dirDest).c_str()); system((string("mkdir -p ") + dirDest).c_str());
...@@ -1078,21 +1100,27 @@ public: ...@@ -1078,21 +1100,27 @@ public:
} }
} }
} }
else { else { // ret == 0
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) {
try { try {
auto resp = json::parse(strResp); auto resp = json::parse(strResp);
//TODO: open this swith when video server has implemented this functionality //TODO: open this swith when video server has implemented this functionality
if(true) { if(true) {
if(resp.count("code") == 0 || resp["code"] != 0) {
bUploadFailed = true;
reportUploadFailure(selfId, true, strResp);
}
if(resp.count("code") != 0 && resp["code"] != 0) { if(resp.count("code") != 0 && resp["code"] != 0) {
bUploadFailed = true;
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"] = 2; 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); string msg = fmt::format("evslicer {} failed to upload videos over N times. reason: {}", selfId, strResp);
spdlog::error(msg);
} }
else { else {
jEvt["cnt"] = jEvt["cnt"].get<int>() - 1; jEvt["cnt"] = jEvt["cnt"].get<int>() - 1;
...@@ -1113,6 +1141,13 @@ public: ...@@ -1113,6 +1141,13 @@ public:
spdlog::error("evslicer {} failed to upload videos. abort retry.", this->selfId); spdlog::error("evslicer {} failed to upload videos. abort retry.", this->selfId);
} }
} }
if(resp.count("code") != 0 && resp["code"] == 0){
if(bUploadFailed) {
bUploadFailed = false;
reportUploadFailure(selfId, false, strResp);
}
}
} }
} }
catch(exception &e) { catch(exception &e) {
...@@ -1121,7 +1156,6 @@ public: ...@@ -1121,7 +1156,6 @@ public:
} }
} }
} }
}
else { else {
spdlog::error("evslicer {} unkown event :{}", this->selfId, evt); spdlog::error("evslicer {} unkown event :{}", this->selfId, evt);
} }
......
...@@ -46,6 +46,7 @@ namespace zmqhelper { ...@@ -46,6 +46,7 @@ namespace zmqhelper {
#define EV_MSG_REPORT_CATID_AVEOF "AV_EOF" #define EV_MSG_REPORT_CATID_AVEOF "AV_EOF"
#define EV_MSG_REPORT_CATID_AVWRITEPIPE "AV_WRITEPIPE" #define EV_MSG_REPORT_CATID_AVWRITEPIPE "AV_WRITEPIPE"
#define EV_MSG_REPORT_CATID_AVLOOPRESTART "AV_LOOPRESTART" #define EV_MSG_REPORT_CATID_AVLOOPRESTART "AV_LOOPRESTART"
#define EV_MSG_REPORT_CATID_AVFAILEDUPLOAD "AV_FAILEDUPLOAD"
#define EV_MSG_META_VALUE_REPORT_LEVEL_INFO "info" #define EV_MSG_META_VALUE_REPORT_LEVEL_INFO "info"
#define EV_MSG_META_VALUE_REPORT_LEVEL_DEBUG "debug" #define EV_MSG_META_VALUE_REPORT_LEVEL_DEBUG "debug"
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论