Make datastore ping interval configurable

And don't bother sending pings more frequently if
the server is struggling to reply to every one.
This commit is contained in:
Mat Sutcliffe
2020-12-19 18:47:41 +00:00
parent 24b9f35653
commit da66aee67d
4 changed files with 12 additions and 10 deletions

View File

@@ -12,6 +12,7 @@
#include "blackmisc/network/networkutils.h"
#include <QNetworkReply>
#include <QDateTime>
#include <QPointer>
using namespace BlackMisc;
@@ -146,19 +147,13 @@ namespace BlackCore
if (m_checkDbAccessibility && m_doDetailedCheck && canConnectDb)
{
// test against real HTTP response
const bool lastHttpSuccess = m_lastClientPingSuccess; // ping result received in meantime
if (lastHttpSuccess && m_totalCheckCount % 10 == 0)
const qint64 pingIntervalSecs = sApp->getGlobalSetup().getDbClientPingIntervalSecs();
if (QDateTime::currentSecsSinceEpoch() >= pingIntervalSecs)
{
// seems to be OK, from time to time ping
m_nextPingSecsSinceEpoch = QDateTime::currentSecsSinceEpoch() + pingIntervalSecs;
this->pingDbClientService(CGlobalSetup::PingStarted);
canConnectDb = m_lastClientPingSuccess;
}
else if (!lastHttpSuccess && m_totalCheckCount % 3 == 0)
{
// not OK, retry more frequently
this->pingDbClientService(CGlobalSetup::PingStarted, true); // force
}
canConnectDb = lastHttpSuccess;
}
bool canConnectInternet = canConnectDb;

View File

@@ -190,6 +190,7 @@ namespace BlackCore
std::atomic_bool m_checkDbAccessibility { true };
std::atomic_bool m_checkSharedUrl { true };
std::atomic_bool m_checkInProgress { false }; //!< a check is currently in progress
std::atomic<qint64> m_nextPingSecsSinceEpoch { 0 }; //!< time at which next ping will be sent
std::atomic_int m_networkAccessibility { QNetworkAccessManager::Accessible }; //!< last state
std::atomic_int m_totalCheckCount { 0 }; //!< counting number of checks
std::atomic_int m_totalBadCountDb { 0 }; //!< Total number of DB failing counts (only real responses when tried)