Do not trigger loads if they are doomed to fail

This commit is contained in:
Klaus Basan
2017-09-27 03:01:03 +02:00
parent f2820ba5a5
commit 15e46ba94a
6 changed files with 37 additions and 3 deletions

View File

@@ -35,6 +35,7 @@
#include "blackmisc/stringutils.h"
#include "blackmisc/threadutils.h"
#include "blackmisc/verify.h"
#include "application.h"
#include <stdbool.h>
#include <stdio.h>
@@ -720,6 +721,12 @@ namespace BlackCore
return m_networkWatchDog && m_networkWatchDog->isSwiftDbAccessible();
}
bool CApplication::hasWorkingSharedUrl() const
{
if (!this->isNetworkAccessible()) { return false; }
return m_networkWatchDog && m_networkWatchDog->hasWorkingSharedUrl();
}
CUrl CApplication::getWorkingSharedUrl() const
{
if (!m_networkWatchDog || !this->isNetworkAccessible()) { return CUrl(); }

View File

@@ -178,6 +178,9 @@ namespace BlackCore
//! \copydoc BlackCore::Db::CNetworkWatchdog::isSwiftDbAccessible
bool isSwiftDbAccessible() const;
//! \copydoc BlackCore::Db::CNetworkWatchdog::hasWorkingSharedUrl
bool hasWorkingSharedUrl() const;
//! \copydoc BlackCore::Db::CNetworkWatchdog::getWorkingSharedUrl
BlackMisc::Network::CUrl getWorkingSharedUrl() const;

View File

@@ -45,16 +45,22 @@ namespace BlackCore
QTimer::singleShot(0, &m_updateTimer, [this] { this->m_updateTimer.start(); }); // restart
}
bool CNetworkWatchdog::hasWorkingSharedUrl() const
{
if (!m_networkAccessible) { return false; }
return !this->getWorkingSharedUrl().isEmpty();
}
CUrl CNetworkWatchdog::getWorkingSharedUrl() const
{
if (!m_networkAccessible) return CUrl();
if (!m_networkAccessible) { return CUrl(); }
QReadLocker l(&m_lockSharedUrl);
return m_workingSharedUrl;
}
int CNetworkWatchdog::triggerCheck()
{
if (!this->doWorkCheck()) return false; // senseless
if (!this->doWorkCheck()) { return false; } // senseless
if (m_checkInProgress) { return -1; }
const int n = this->getCheckCount();

View File

@@ -62,6 +62,10 @@ namespace BlackCore
//! \threadsafe
bool isInternetAccessible() const { return m_internetAccessible; }
//! Has working shared URL?
//! \threadsafe
bool hasWorkingSharedUrl() const;
//! A working shared URL
//! \threadsafe
BlackMisc::Network::CUrl getWorkingSharedUrl() const;

View File

@@ -269,6 +269,13 @@ namespace BlackCore
CEntityFlags::Entity CWebDataServices::triggerLoadingDirectlyFromDb(CEntityFlags::Entity whatToRead, const QDateTime &newerThan)
{
if (m_shuttingDown) { return CEntityFlags::NoEntity; }
if (!sApp || sApp->isShuttingDown()) { return CEntityFlags::NoEntity; }
if (!sApp->isSwiftDbAccessible())
{
CLogMessage(this).warning("Not triggering load of '%1' because swift DB is not accessible") << CEntityFlags::flagToString(whatToRead);
return CEntityFlags::NoEntity;
}
CEntityFlags::Entity triggeredRead = CEntityFlags::NoEntity;
if (m_dbInfoDataReader)
{
@@ -312,6 +319,13 @@ namespace BlackCore
CEntityFlags::Entity CWebDataServices::triggerLoadingDirectlyFromSharedFiles(CEntityFlags::Entity whatToRead, bool checkCacheTsUpfront)
{
if (m_shuttingDown) { return CEntityFlags::NoEntity; }
if (!sApp || sApp->isShuttingDown()) { return CEntityFlags::NoEntity; }
if (!sApp->hasWorkingSharedUrl())
{
CLogMessage(this).warning("Not triggering load of '%1' because no working shared URL") << CEntityFlags::flagToString(whatToRead);
return CEntityFlags::NoEntity;
}
CEntityFlags::Entity triggeredRead = CEntityFlags::NoEntity;
this->triggerReadOfSharedInfoObjects(); // trigger reload of info objects (for shared)

View File

@@ -523,7 +523,7 @@ namespace BlackCore
BlackMisc::Network::CEntityFlags::Entity m_swiftDbEntitiesRead = BlackMisc::Network::CEntityFlags::NoEntity; //!< entities read
BlackCore::Db::CDatabaseReaderConfigList m_dbReaderConfig; //!< how to read DB data
bool m_initialRead = false; //!< initial read started
bool m_signalledHeaders = false; //!< haders loading has been signalled
bool m_signalledHeaders = false; //!< headers loading has been signalled
bool m_shuttingDown = false; //!< shutting down?
QDateTime m_dbInfoObjectTimeout; //!< started reading DB info objects
QDateTime m_sharedInfoObjectsTimeout; //!< started reading shared info objects