DB reader, doWorkCheck before writing cache. In case shutdown takes place in-between.

This commit is contained in:
Klaus Basan
2018-04-04 00:04:04 +02:00
parent 57b3760b61
commit 7d106acdee
4 changed files with 10 additions and 3 deletions

View File

@@ -215,6 +215,7 @@ namespace BlackCore
Q_FUNC_INFO);
}
if (!this->doWorkCheck()) { return; }
const int size = airports.size();
qint64 latestTimestamp = airports.latestTimestampMsecsSinceEpoch();
if (size > 0 && latestTimestamp < 0)

View File

@@ -292,6 +292,7 @@ namespace BlackCore
Q_FUNC_INFO);
}
if (!this->doWorkCheck()) { return; }
const int n = codes.size();
qint64 latestTimestamp = codes.latestTimestampMsecsSinceEpoch(); // ignores duplicates
if (n > 0 && latestTimestamp < 0)
@@ -342,6 +343,7 @@ namespace BlackCore
Q_FUNC_INFO);
}
if (!this->doWorkCheck()) { return; }
const int n = codes.size();
qint64 latestTimestamp = codes.latestTimestampMsecsSinceEpoch();
if (n > 0 && latestTimestamp < 0)
@@ -382,6 +384,7 @@ namespace BlackCore
countries = CCountryList::fromDatabaseJson(res);
}
if (!this->doWorkCheck()) { return; }
const int n = countries.size();
qint64 latestTimestamp = countries.latestTimestampMsecsSinceEpoch();
if (n > 0 && latestTimestamp < 0)

View File

@@ -301,6 +301,7 @@ namespace BlackCore
liveries = CLiveryList::fromDatabaseJson(res);
}
if (!this->doWorkCheck()) { return; }
const int n = liveries.size();
qint64 latestTimestamp = liveries.latestTimestampMsecsSinceEpoch();
if (n > 0 && latestTimestamp < 0)
@@ -343,6 +344,7 @@ namespace BlackCore
distributors = CDistributorList::fromDatabaseJson(res);
}
if (!this->doWorkCheck()) { return; }
const int n = distributors.size();
qint64 latestTimestamp = distributors.latestTimestampMsecsSinceEpoch();
if (n > 0 && latestTimestamp < 0)
@@ -386,6 +388,7 @@ namespace BlackCore
}
// synchronized update
if (!this->doWorkCheck()) { return; }
const int n = models.size();
qint64 latestTimestamp = models.latestTimestampMsecsSinceEpoch();
if (n > 0 && latestTimestamp < 0)

View File

@@ -157,7 +157,7 @@ namespace BlackCore
void CThreadedReader::doWork()
{
if (!doWorkCheck()) { return; }
doWorkImpl();
this->doWorkImpl();
Q_ASSERT(m_periodicTime > 0);
m_updateTimer.start(m_periodicTime); // restart
}
@@ -165,8 +165,8 @@ namespace BlackCore
bool CThreadedReader::doWorkCheck() const
{
// sApp->hasWebDataServices() cannot be used, as some readers are already used during init phase
if (!isEnabled()) { return false; }
if (isAbandoned()) { return false; }
if (!this->isEnabled()) { return false; }
if (this->isAbandoned()) { return false; }
if (!m_unitTest && (!sApp || sApp->isShuttingDown())) { return false; }
return true;
}