mirror of
https://gitlab.com/spaceti-app/integrations/acs/colnod-connector.git
synced 2026-07-12 10:50:38 +02:00
add check of time offset
This commit is contained in:
parent
b031741b88
commit
14e0e421ba
@ -153,7 +153,7 @@ void DatabaseAPI::reupdateDeleted(const QList<QString>& ids)
|
||||
{
|
||||
auto query = mDbMan->createQuery();
|
||||
for (const auto &id : ids){
|
||||
query.prepare("UPDATE colnod_token SET last_update = CURRENT_TIMESTAMP() WHERE id = :id");
|
||||
query.prepare("UPDATE colnod_token SET last_update = now() WHERE id = :id");
|
||||
// query.bindValue(":last_update", QDateTime::fromMSecsSinceEpoch(getNow()).toString("yyyy-MM-dd hh:mm:ss.zzz"));
|
||||
// QString tempId = "'" + id + "'";
|
||||
query.bindValue(":id", id);
|
||||
|
||||
@ -107,9 +107,11 @@ void SyncManager::init() {
|
||||
return;
|
||||
}
|
||||
Timestamp time;
|
||||
time.setTimestamp(syncBegin - 100 * 1000);
|
||||
qint64 offset = 5 * 1000;
|
||||
time.setTimestamp(syncBegin - offset);
|
||||
|
||||
auto tokensRequest = colnod->getTokensUpdated(time);
|
||||
auto timeCompare = QDateTime::currentDateTime();
|
||||
|
||||
// updated data are ready
|
||||
|
||||
@ -122,6 +124,23 @@ void SyncManager::init() {
|
||||
emit end();
|
||||
return;
|
||||
}
|
||||
|
||||
// check time offset
|
||||
if (!preparedData->databaseData->updatedTokens.isEmpty() && uploadedData->updatedTokens.isEmpty()) {
|
||||
qCritical(syncmanager) << "Offset with colnod time is greater than 5 seconds";
|
||||
emit end();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!uploadedData->updatedTokens.isEmpty()) {
|
||||
auto diff = uploadedData->updatedTokens[0]->lastUpdate().secsTo(timeCompare);
|
||||
if ( diff > 1 || diff < -1) {
|
||||
qCritical(syncmanager) << "Offset with colnod time is:" << diff << "seconds";
|
||||
emit end();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!database->uploadTokens(uploadedData->updatedTokens, {"lastModified"})) {
|
||||
qCritical(syncmanager) << "Not possible to upload data to database";
|
||||
emit end();
|
||||
@ -164,7 +183,7 @@ bool SyncManager::startSynchronization()
|
||||
emit end();
|
||||
return false;
|
||||
}
|
||||
qint64 offset = 75 * 1000;
|
||||
qint64 offset = 0 * 1000;
|
||||
qInfo(syncmanager) << tab << "Begin sync ( previous sync" << mlastSync.toDateString() << ")";
|
||||
|
||||
colnod->downloadData(mlastSync.timestamp() - offset);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user