(cobra bots) add a --heartbeat_timeout option to specify when the bot should terminate because no events are received

This commit is contained in:
Benjamin Sergeant
2020-05-06 22:01:48 -07:00
parent c030a62c8b
commit 0772ef7ef5
15 changed files with 58 additions and 14 deletions

View File

@ -22,6 +22,7 @@ namespace ix
const std::string& filter,
const std::string& position,
bool enableHeartbeat,
int heartBeatTimeout,
int runtime)
{
ix::CobraConnection conn;
@ -78,7 +79,7 @@ namespace ix
std::thread t1(timer);
auto heartbeat = [&sentCount, &receivedCount, &stop, &enableHeartbeat] {
auto heartbeat = [&sentCount, &receivedCount, &stop, &enableHeartbeat, &heartBeatTimeout] {
std::string state("na");
if (!enableHeartbeat) return;
@ -94,11 +95,12 @@ namespace ix
if (currentState == state)
{
CoreLogger::error("no messages received or sent for 1 minute, exiting");
exit(1);
fatalCobraError = true;
break;
}
state = currentState;
auto duration = std::chrono::minutes(1);
auto duration = std::chrono::seconds(heartBeatTimeout);
std::this_thread::sleep_for(duration);
}

View File

@ -30,6 +30,7 @@ namespace ix
const std::string& filter,
const std::string& position,
bool enableHeartbeat,
int heartBeatTimeout,
int runtime);
void setOnBotMessageCallback(const OnBotMessageCallback& callback);

View File

@ -23,6 +23,7 @@ namespace ix
SentryClient& sentryClient,
bool verbose,
bool enableHeartbeat,
int heartBeatTimeout,
int runtime)
{
CobraBot bot;
@ -81,6 +82,7 @@ namespace ix
filter,
position,
enableHeartbeat,
heartBeatTimeout,
runtime);
}
} // namespace ix

View File

@ -19,5 +19,6 @@ namespace ix
SentryClient& sentryClient,
bool verbose,
bool enableHeartbeat,
int heartBeatTimeout,
int runtime);
} // namespace ix

View File

@ -63,6 +63,7 @@ namespace ix
const std::string& timer,
bool verbose,
bool enableHeartbeat,
int heartBeatTimeout,
int runtime)
{
ix::CobraConnection conn;
@ -146,6 +147,7 @@ namespace ix
filter,
position,
enableHeartbeat,
heartBeatTimeout,
runtime);
}
} // namespace ix

View File

@ -23,5 +23,6 @@ namespace ix
const std::string& timer,
bool verbose,
bool enableHeartbeat,
int heartBeatTimeout,
int runtime);
} // namespace ix

View File

@ -70,6 +70,7 @@ namespace ix
bool fluentd,
bool quiet,
bool enableHeartbeat,
int heartBeatTimeout,
int runtime)
{
CobraBot bot;
@ -93,6 +94,7 @@ namespace ix
filter,
position,
enableHeartbeat,
heartBeatTimeout,
runtime);
}
} // namespace ix

View File

@ -19,5 +19,6 @@ namespace ix
bool fluentd,
bool quiet,
bool enableHeartbeat,
int heartBeatTimeout,
int runtime);
} // namespace ix