mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-25 22:54:57 +02:00
RedisConnection#Connect(): don't give up
This commit is contained in:
parent
e7ce71095a
commit
e522db20b1
@ -9,9 +9,9 @@
|
||||
#include "base/objectlock.hpp"
|
||||
#include "base/string.hpp"
|
||||
#include "base/tcpsocket.hpp"
|
||||
#include <boost/asio/post.hpp>
|
||||
#include <boost/asio/spawn.hpp>
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/coroutine/exceptions.hpp>
|
||||
#include <boost/date_time/posix_time/posix_time_duration.hpp>
|
||||
#include <boost/utility/string_view.hpp>
|
||||
#include <boost/variant/get.hpp>
|
||||
#include <exception>
|
||||
@ -144,6 +144,9 @@ void RedisConnection::Connect(asio::yield_context& yc)
|
||||
{
|
||||
Defer notConnecting ([this]() { m_Connecting.store(m_Connected.load()); });
|
||||
|
||||
boost::asio::deadline_timer timer (m_Strand.context());
|
||||
|
||||
for (;;) {
|
||||
try {
|
||||
if (m_Path.IsEmpty()) {
|
||||
Log(LogInformation, "IcingaDB")
|
||||
@ -164,12 +167,19 @@ void RedisConnection::Connect(asio::yield_context& yc)
|
||||
m_Connected.store(true);
|
||||
|
||||
Log(LogInformation, "IcingaDB", "Connected to Redis server");
|
||||
|
||||
break;
|
||||
} catch (const boost::coroutines::detail::forced_unwind&) {
|
||||
throw;
|
||||
} catch (const std::exception& ex) {
|
||||
Log(LogCritical, "IcingaDB")
|
||||
<< "Cannot connect to " << m_Host << ":" << m_Port << ": " << ex.what();
|
||||
}
|
||||
|
||||
timer.expires_from_now(boost::posix_time::seconds(5));
|
||||
timer.async_wait(yc);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void RedisConnection::ReadLoop(asio::yield_context& yc)
|
||||
|
Loading…
x
Reference in New Issue
Block a user