From 60a301a93b6057bb2c54ac04a7c38c38389037b3 Mon Sep 17 00:00:00 2001 From: Dark1-dev Date: Wed, 1 Mar 2023 21:30:57 +0600 Subject: Add files via upload --- src/TcpTasks/Updater/onsynctickeraction.cpp | 20 +++++++++++++++++ src/TcpTasks/Updater/scheduleupdater.cpp | 29 +++++++++++++++++++++++++ src/TcpTasks/Updater/syncupdater.cpp | 7 ++++++ src/TcpTasks/Updater/syncupdater.h | 33 +++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+) create mode 100644 src/TcpTasks/Updater/onsynctickeraction.cpp create mode 100644 src/TcpTasks/Updater/scheduleupdater.cpp create mode 100644 src/TcpTasks/Updater/syncupdater.cpp create mode 100644 src/TcpTasks/Updater/syncupdater.h (limited to 'src/TcpTasks/Updater') diff --git a/src/TcpTasks/Updater/onsynctickeraction.cpp b/src/TcpTasks/Updater/onsynctickeraction.cpp new file mode 100644 index 0000000..53214ce --- /dev/null +++ b/src/TcpTasks/Updater/onsynctickeraction.cpp @@ -0,0 +1,20 @@ +#include "syncupdater.h" + +void SyncUpdater::onSyncTickerAction() +{ + // exists? + if ( _syncIndex < _coreObject->Settings.SyncerSettings.syncServers.length() ) + { + // retrieve sync settings from config + SyncServer syncServ = _coreObject->Settings.SyncerSettings.syncServers.at(_syncIndex); + _syncIndex++; + + // execute sync with remote masterserver + new SyncClient(_coreObject, syncServ.remoteAddress, syncServ.listenPort); + } + else + { + // last entry. turn off timer + _syncTicker.stop(); + } +} diff --git a/src/TcpTasks/Updater/scheduleupdater.cpp b/src/TcpTasks/Updater/scheduleupdater.cpp new file mode 100644 index 0000000..7a96d6e --- /dev/null +++ b/src/TcpTasks/Updater/scheduleupdater.cpp @@ -0,0 +1,29 @@ +#include "syncupdater.h" + +bool SyncUpdater::scheduleUpdater() +{ + // schedule sync X seconds apart (prevent network spikes) + connect(&_syncTicker, &QTimer::timeout, this, &SyncUpdater::onSyncTickerAction); + _syncTicker.setInterval( _graceTime_ms ); + + // set update timer + connect(&_updaterTimer, &QTimer::timeout, [this] + { + // reset and start ticker + _syncIndex = 0; + _syncTicker.start(); + }); + + _updaterTimer.setInterval( _coreObject->Settings.SyncerSettings.syncInterval_s * 1000); + _updaterTimer.start(); + + // complete startup + _coreObject->Log.logEvent("info", QStringLiteral("sync with other masterservers every %1 seconds") + .arg(_coreObject->Settings.SyncerSettings.syncInterval_s)); + + // run immediately at startup + _syncIndex = 0; + _syncTicker.start(); + + return true; +} diff --git a/src/TcpTasks/Updater/syncupdater.cpp b/src/TcpTasks/Updater/syncupdater.cpp new file mode 100644 index 0000000..da52f12 --- /dev/null +++ b/src/TcpTasks/Updater/syncupdater.cpp @@ -0,0 +1,7 @@ +#include "syncupdater.h" + +SyncUpdater::SyncUpdater(const QSharedPointer &coreObject) +{ + // create local access + this->_coreObject = coreObject; +} diff --git a/src/TcpTasks/Updater/syncupdater.h b/src/TcpTasks/Updater/syncupdater.h new file mode 100644 index 0000000..9bd2299 --- /dev/null +++ b/src/TcpTasks/Updater/syncupdater.h @@ -0,0 +1,33 @@ +#ifndef SYNCUPDATER_H +#define SYNCUPDATER_H + +#include +#include + +#include "Core/CoreObject/coreobject.h" +#include "Database/Common/commonactions.h" +#include "TcpTasks/SyncClient/syncclient.h" + +class SyncUpdater: public QObject +{ + Q_OBJECT +public: + SyncUpdater(const QSharedPointer &coreObject); + bool scheduleUpdater(); + +private: + QSharedPointer _coreObject; + const int _graceTime_ms = 5000; + + // update/ticker timer + QTimer _updaterTimer; + QTimer _syncTicker; + + // index + int _syncIndex = 0; + +private slots: + void onSyncTickerAction(); +}; + +#endif // SYNCUPDATER_H -- cgit v1.2.3