diff --git a/resources/share/shared/bootstrap/bootstrap.json b/resources/share/shared/bootstrap/bootstrap.json index 8180655f2..bb9ccb1dd 100644 --- a/resources/share/shared/bootstrap/bootstrap.json +++ b/resources/share/shared/bootstrap/bootstrap.json @@ -38,6 +38,7 @@ } ] }, + "pingIntervalSecs": 180, "predefinedServers": { "containerbase": [ ] diff --git a/src/blackcore/data/globalsetup.h b/src/blackcore/data/globalsetup.h index e8a0e6ea1..640d8aa9c 100644 --- a/src/blackcore/data/globalsetup.h +++ b/src/blackcore/data/globalsetup.h @@ -150,6 +150,9 @@ namespace BlackCore //! Ping the DB server, fire and forget (no feedback etc) BlackMisc::Network::CUrl getDbClientPingServiceUrl(PingType type) const; + //! Seconds between pings + qint64 getDbClientPingIntervalSecs() const { return m_pingIntervalSecs; } + //! alpha XSwiftBus files available BlackMisc::Network::CUrl getAlphaXSwiftBusFilesServiceUrl() const; @@ -245,6 +248,7 @@ namespace BlackCore bool m_wasLoadedFromFile = false; //!< Loaded from local file int m_dbHttpPort = 80; //!< port int m_dbHttpsPort = 443; //!< SSL port + qint64 m_pingIntervalSecs = 180; //!< seconds between datastore pings bool m_development = false; //!< dev. version? QString m_mappingMinimumVersion; //!< minimum version BlackMisc::Network::CUrl m_crashReportServerUrl; //!< crash report server @@ -276,6 +280,7 @@ namespace BlackCore BLACK_METAMEMBER(dbRootDirectoryUrl), BLACK_METAMEMBER(dbHttpPort), BLACK_METAMEMBER(dbHttpsPort), + BLACK_METAMEMBER(pingIntervalSecs), BLACK_METAMEMBER(vatsimStatusFileUrls), BLACK_METAMEMBER(vatsimDataFileUrls), BLACK_METAMEMBER(vatsimBookingsUrl), diff --git a/src/blackcore/db/networkwatchdog.cpp b/src/blackcore/db/networkwatchdog.cpp index 2af2a7c2d..6edb76c67 100644 --- a/src/blackcore/db/networkwatchdog.cpp +++ b/src/blackcore/db/networkwatchdog.cpp @@ -12,6 +12,7 @@ #include "blackmisc/network/networkutils.h" #include +#include #include 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; diff --git a/src/blackcore/db/networkwatchdog.h b/src/blackcore/db/networkwatchdog.h index 6114b61c7..c50ed1d7d 100644 --- a/src/blackcore/db/networkwatchdog.h +++ b/src/blackcore/db/networkwatchdog.h @@ -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 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)