Retry consul connection attempts and then die

This commit is contained in:
Vitaliy Filippov
2020-04-15 15:33:18 +03:00
parent d78ce509c6
commit 089b4eb208
4 changed files with 33 additions and 1 deletions
+18
View File
@@ -132,9 +132,27 @@ void osd_t::report_status()
{
int pos = res.find("\r\n\r\n");
if (pos >= 0)
{
res = res.substr(pos+4);
}
if (err != 0 || res != "true")
{
consul_failed_attempts++;
printf("Error reporting state to Consul: code %d (%s), response text: %s\n", err, strerror(err), res.c_str());
if (consul_failed_attempts > MAX_CONSUL_ATTEMPTS)
{
throw std::runtime_error("Cluster connection failed");
}
// Retry
tfd->set_timer(CONSUL_RETRY_INTERVAL, false, [this](int timer_id)
{
report_status();
});
}
else
{
consul_failed_attempts = 0;
}
});
}