Added timeout support to analysers in validate mode

This commit is contained in:
Thulinma 2018-01-17 11:28:04 +01:00
parent 0c6cd9bfc6
commit 8c3b8d9666
2 changed files with 28 additions and 1 deletions

View file

@ -6,6 +6,7 @@
Analyser::Analyser(Util::Config &conf){
validate = conf.getBool("validate");
detail = conf.getInteger("detail");
timeOut = conf.getInteger("timeout");
mediaTime = 0;
upTime = Util::bootSecs();
isActive = &conf.is_active;
@ -61,9 +62,26 @@ int Analyser::run(Util::Config &conf){
}
if (validate){
finTime = Util::bootSecs();
//slow down to realtime + 10s
if (validate && ((finTime - upTime + 10) * 1000 < mediaTime)){
uint32_t sleepMs = mediaTime - (Util::bootSecs() - upTime + 10) * 1000;
if ((finTime - upTime + sleepMs / 1000) >= timeOut){
WARN_MSG("Reached timeout of %llu seconds, stopping", timeOut);
return 3;
}
INFO_MSG("Sleeping for %lums", sleepMs);
Util::sleep(sleepMs);
finTime = Util::bootSecs();
}
if ((finTime - upTime) > (mediaTime / 1000) + 2){
FAIL_MSG("Media time more than 2 seconds behind!");
return 1;
return 4;
}
if ((finTime - upTime) >= timeOut){
WARN_MSG("Reached timeout of %llu seconds, stopping", timeOut);
return 3;
}
}
}
@ -88,6 +106,14 @@ void Analyser::init(Util::Config &conf){
conf.addOption("validate", opt);
opt.null();
opt["long"] = "timeout";
opt["short"] = "T";
opt["arg"] = "num";
opt["default"] = 0ll;
opt["help"] = "Time out after X seconds of processing/retrieving";
conf.addOption("timeout", opt);
opt.null();
opt["long"] = "detail";
opt["short"] = "D";
opt["arg"] = "num";

View file

@ -31,6 +31,7 @@ public:
protected:
// These hold the current state and/or config
bool validate; ///< True of validation mode is enabled
uint64_t timeOut; ///< After how many seconds a timeout should trigger
int detail; ///< Detail level of analyser
uint64_t mediaTime; ///< Timestamp in ms of last media packet received
uint64_t upTime; ///< Unix time of analyser start