Add exception handler for Redis WorkQueue

refs #4991
This commit is contained in:
Michael Friedrich 2017-03-24 15:18:37 +01:00
parent a5556cbaae
commit af3e2c429f
2 changed files with 18 additions and 1 deletions

View File

@ -42,6 +42,8 @@ void RedisWriter::Start(bool runtimeCreated)
m_ConfigDumpInProgress = false;
m_WorkQueue.SetExceptionCallback(boost::bind(&RedisWriter::ExceptionHandler, this, _1));
m_ReconnectTimer = new Timer();
m_ReconnectTimer->SetInterval(15);
m_ReconnectTimer->OnTimerExpired.connect(boost::bind(&RedisWriter::ReconnectTimerHandler, this));
@ -57,6 +59,19 @@ void RedisWriter::Start(bool runtimeCreated)
thread.detach();
}
void RedisWriter::ExceptionHandler(boost::exception_ptr exp)
{
Log(LogCritical, "RedisWriter", "Exception during redis query. Verify that Redis is operational.");
Log(LogDebug, "RedisWriter")
<< "Exception during redis operation: " << DiagnosticInformation(exp);
if (m_Context) {
redisFree(m_Context);
m_Context = NULL;
}
}
void RedisWriter::ReconnectTimerHandler(void)
{
m_WorkQueue.Enqueue(boost::bind(&RedisWriter::TryToReconnect, this));
@ -275,7 +290,7 @@ boost::shared_ptr<redisReply> RedisWriter::ExecuteQuery(const std::vector<String
delete [] argvlen;
if (reply->type == REDIS_REPLY_ERROR) {
Log(LogInformation, "RedisWriter")
Log(LogCritical, "RedisWriter")
<< "Redis query failed: " << reply->str;
String msg = reply->str;

View File

@ -82,6 +82,8 @@ private:
void AssertOnWorkQueue(void);
void ExceptionHandler(boost::exception_ptr exp);
boost::shared_ptr<redisReply> ExecuteQuery(const std::vector<String>& query);
Timer::Ptr m_ReconnectTimer;