refactor(Core/Time): Introduce GetExpirationTime instead of calculati… (#21006)
This commit is contained in:
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the AzerothCore Project. See AUTHORS file for Copyright information
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU Affero General Public License as published by the
|
||||||
|
* Free Software Foundation; either version 3 of the License, or (at your
|
||||||
|
* option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _STEADYTIMER_H
|
||||||
|
#define _STEADYTIMER_H
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
namespace Acore::Asio::SteadyTimer
|
||||||
|
{
|
||||||
|
inline auto GetExpirationTime(int32 seconds)
|
||||||
|
{
|
||||||
|
return std::chrono::steady_clock::now() + std::chrono::seconds(seconds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // _STEADYTIMER_H
|
||||||
@@ -18,6 +18,7 @@
|
|||||||
#include "Metric.h"
|
#include "Metric.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
|
#include "SteadyTimer.h"
|
||||||
#include "Strand.h"
|
#include "Strand.h"
|
||||||
#include "Tokenize.h"
|
#include "Tokenize.h"
|
||||||
#include <boost/algorithm/string/replace.hpp>
|
#include <boost/algorithm/string/replace.hpp>
|
||||||
@@ -246,9 +247,7 @@ void Metric::ScheduleSend()
|
|||||||
{
|
{
|
||||||
if (_enabled)
|
if (_enabled)
|
||||||
{
|
{
|
||||||
// Calculate the expiration time
|
_batchTimer->expires_at(Acore::Asio::SteadyTimer::GetExpirationTime(_updateInterval));
|
||||||
auto expirationTime = std::chrono::steady_clock::now() + std::chrono::seconds(_updateInterval);
|
|
||||||
_batchTimer->expires_at(expirationTime);
|
|
||||||
_batchTimer->async_wait(std::bind(&Metric::SendBatch, this));
|
_batchTimer->async_wait(std::bind(&Metric::SendBatch, this));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -281,9 +280,7 @@ void Metric::ScheduleOverallStatusLog()
|
|||||||
{
|
{
|
||||||
if (_enabled)
|
if (_enabled)
|
||||||
{
|
{
|
||||||
// Calculate the expiration time _overallStatusTimerInterval from now
|
_overallStatusTimer->expires_at(Acore::Asio::SteadyTimer::GetExpirationTime(_overallStatusTimerInterval));
|
||||||
auto expirationTime = std::chrono::steady_clock::now() + std::chrono::seconds(_overallStatusTimerInterval);
|
|
||||||
_overallStatusTimer->expires_at(expirationTime);
|
|
||||||
_overallStatusTimer->async_wait([this](const boost::system::error_code&)
|
_overallStatusTimer->async_wait([this](const boost::system::error_code&)
|
||||||
{
|
{
|
||||||
_overallStatusTimerTriggered = true;
|
_overallStatusTimerTriggered = true;
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
#include "RealmList.h"
|
#include "RealmList.h"
|
||||||
#include "SecretMgr.h"
|
#include "SecretMgr.h"
|
||||||
#include "SharedDefines.h"
|
#include "SharedDefines.h"
|
||||||
|
#include "SteadyTimer.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include <boost/asio/signal_set.hpp>
|
#include <boost/asio/signal_set.hpp>
|
||||||
#include <boost/program_options.hpp>
|
#include <boost/program_options.hpp>
|
||||||
@@ -179,17 +180,13 @@ int main(int argc, char** argv)
|
|||||||
int32 dbPingInterval = sConfigMgr->GetOption<int32>("MaxPingTime", 30);
|
int32 dbPingInterval = sConfigMgr->GetOption<int32>("MaxPingTime", 30);
|
||||||
std::shared_ptr<boost::asio::steady_timer> dbPingTimer = std::make_shared<boost::asio::steady_timer>(*ioContext);
|
std::shared_ptr<boost::asio::steady_timer> dbPingTimer = std::make_shared<boost::asio::steady_timer>(*ioContext);
|
||||||
|
|
||||||
// Calculate the expiration time
|
dbPingTimer->expires_at(Acore::Asio::SteadyTimer::GetExpirationTime(dbPingInterval * MINUTE));
|
||||||
auto expirationTime = std::chrono::steady_clock::now() + std::chrono::seconds(dbPingInterval);
|
|
||||||
dbPingTimer->expires_at(expirationTime);
|
|
||||||
dbPingTimer->async_wait(std::bind(&KeepDatabaseAliveHandler, std::weak_ptr<boost::asio::steady_timer>(dbPingTimer), dbPingInterval, std::placeholders::_1));
|
dbPingTimer->async_wait(std::bind(&KeepDatabaseAliveHandler, std::weak_ptr<boost::asio::steady_timer>(dbPingTimer), dbPingInterval, std::placeholders::_1));
|
||||||
|
|
||||||
int32 banExpiryCheckInterval = sConfigMgr->GetOption<int32>("BanExpiryCheckInterval", 60);
|
int32 banExpiryCheckInterval = sConfigMgr->GetOption<int32>("BanExpiryCheckInterval", 60);
|
||||||
std::shared_ptr<boost::asio::steady_timer> banExpiryCheckTimer = std::make_shared<boost::asio::steady_timer>(*ioContext);
|
std::shared_ptr<boost::asio::steady_timer> banExpiryCheckTimer = std::make_shared<boost::asio::steady_timer>(*ioContext);
|
||||||
|
|
||||||
// Calculate the expiration time
|
banExpiryCheckTimer->expires_at(Acore::Asio::SteadyTimer::GetExpirationTime(banExpiryCheckInterval));
|
||||||
auto expirationTimeBanExpiry = std::chrono::steady_clock::now() + std::chrono::seconds(banExpiryCheckInterval);
|
|
||||||
banExpiryCheckTimer->expires_at(expirationTimeBanExpiry);
|
|
||||||
banExpiryCheckTimer->async_wait(std::bind(&BanExpiryHandler, std::weak_ptr<boost::asio::steady_timer>(banExpiryCheckTimer), banExpiryCheckInterval, std::placeholders::_1));
|
banExpiryCheckTimer->async_wait(std::bind(&BanExpiryHandler, std::weak_ptr<boost::asio::steady_timer>(banExpiryCheckTimer), banExpiryCheckInterval, std::placeholders::_1));
|
||||||
|
|
||||||
// Start the io service worker loop
|
// Start the io service worker loop
|
||||||
@@ -252,9 +249,7 @@ void KeepDatabaseAliveHandler(std::weak_ptr<boost::asio::steady_timer> dbPingTim
|
|||||||
LOG_INFO("server.authserver", "Ping MySQL to keep connection alive");
|
LOG_INFO("server.authserver", "Ping MySQL to keep connection alive");
|
||||||
LoginDatabase.KeepAlive();
|
LoginDatabase.KeepAlive();
|
||||||
|
|
||||||
// Calculate the expiration time
|
dbPingTimer->expires_at(Acore::Asio::SteadyTimer::GetExpirationTime(dbPingInterval));
|
||||||
auto expirationTime = std::chrono::steady_clock::now() + std::chrono::seconds(dbPingInterval);
|
|
||||||
dbPingTimer->expires_at(expirationTime);
|
|
||||||
dbPingTimer->async_wait(std::bind(&KeepDatabaseAliveHandler, dbPingTimerRef, dbPingInterval, std::placeholders::_1));
|
dbPingTimer->async_wait(std::bind(&KeepDatabaseAliveHandler, dbPingTimerRef, dbPingInterval, std::placeholders::_1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -269,9 +264,7 @@ void BanExpiryHandler(std::weak_ptr<boost::asio::steady_timer> banExpiryCheckTim
|
|||||||
LoginDatabase.Execute(LoginDatabase.GetPreparedStatement(LOGIN_DEL_EXPIRED_IP_BANS));
|
LoginDatabase.Execute(LoginDatabase.GetPreparedStatement(LOGIN_DEL_EXPIRED_IP_BANS));
|
||||||
LoginDatabase.Execute(LoginDatabase.GetPreparedStatement(LOGIN_UPD_EXPIRED_ACCOUNT_BANS));
|
LoginDatabase.Execute(LoginDatabase.GetPreparedStatement(LOGIN_UPD_EXPIRED_ACCOUNT_BANS));
|
||||||
|
|
||||||
// Calculate the expiration time
|
banExpiryCheckTimer->expires_at(Acore::Asio::SteadyTimer::GetExpirationTime(banExpiryCheckInterval));
|
||||||
auto expirationTime = std::chrono::steady_clock::now() + std::chrono::seconds(banExpiryCheckInterval);
|
|
||||||
banExpiryCheckTimer->expires_at(expirationTime);
|
|
||||||
banExpiryCheckTimer->async_wait(std::bind(&BanExpiryHandler, banExpiryCheckTimerRef, banExpiryCheckInterval, std::placeholders::_1));
|
banExpiryCheckTimer->async_wait(std::bind(&BanExpiryHandler, banExpiryCheckTimerRef, banExpiryCheckInterval, std::placeholders::_1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,7 @@
|
|||||||
#include "ScriptMgr.h"
|
#include "ScriptMgr.h"
|
||||||
#include "SecretMgr.h"
|
#include "SecretMgr.h"
|
||||||
#include "SharedDefines.h"
|
#include "SharedDefines.h"
|
||||||
|
#include "SteadyTimer.h"
|
||||||
#include "World.h"
|
#include "World.h"
|
||||||
#include "WorldSocket.h"
|
#include "WorldSocket.h"
|
||||||
#include "WorldSocketMgr.h"
|
#include "WorldSocketMgr.h"
|
||||||
@@ -90,9 +91,7 @@ public:
|
|||||||
|
|
||||||
static void Start(std::shared_ptr<FreezeDetector> const& freezeDetector)
|
static void Start(std::shared_ptr<FreezeDetector> const& freezeDetector)
|
||||||
{
|
{
|
||||||
// Calculate the expiration time 5seconds from now
|
freezeDetector->_timer.expires_at(Acore::Asio::SteadyTimer::GetExpirationTime(5));
|
||||||
auto expirationTime = std::chrono::steady_clock::now() + std::chrono::seconds(5);
|
|
||||||
freezeDetector->_timer.expires_at(expirationTime);
|
|
||||||
freezeDetector->_timer.async_wait(std::bind(&FreezeDetector::Handler, std::weak_ptr<FreezeDetector>(freezeDetector), std::placeholders::_1));
|
freezeDetector->_timer.async_wait(std::bind(&FreezeDetector::Handler, std::weak_ptr<FreezeDetector>(freezeDetector), std::placeholders::_1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -632,9 +631,7 @@ void FreezeDetector::Handler(std::weak_ptr<FreezeDetector> freezeDetectorRef, bo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate the expiration time
|
freezeDetector->_timer.expires_at(Acore::Asio::SteadyTimer::GetExpirationTime(1));
|
||||||
auto expirationTime = std::chrono::steady_clock::now() + std::chrono::seconds(1);
|
|
||||||
freezeDetector->_timer.expires_at(expirationTime);
|
|
||||||
freezeDetector->_timer.async_wait(std::bind(&FreezeDetector::Handler, freezeDetectorRef, std::placeholders::_1));
|
freezeDetector->_timer.async_wait(std::bind(&FreezeDetector::Handler, freezeDetectorRef, std::placeholders::_1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,8 +18,9 @@
|
|||||||
#include "RealmList.h"
|
#include "RealmList.h"
|
||||||
#include "DatabaseEnv.h"
|
#include "DatabaseEnv.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "Resolver.h"
|
|
||||||
#include "QueryResult.h"
|
#include "QueryResult.h"
|
||||||
|
#include "Resolver.h"
|
||||||
|
#include "SteadyTimer.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include <boost/asio/ip/tcp.hpp>
|
#include <boost/asio/ip/tcp.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@@ -227,9 +228,7 @@ void RealmList::UpdateRealms(boost::system::error_code const& error)
|
|||||||
|
|
||||||
if (_updateInterval)
|
if (_updateInterval)
|
||||||
{
|
{
|
||||||
// Calculate the expiration time _updateInterval from now
|
_updateTimer->expires_at(Acore::Asio::SteadyTimer::GetExpirationTime(_updateInterval));
|
||||||
auto expiration_time = std::chrono::steady_clock::now() + std::chrono::seconds(_updateInterval);
|
|
||||||
_updateTimer->expires_at(expiration_time);
|
|
||||||
_updateTimer->async_wait([this](boost::system::error_code const& errorCode){ UpdateRealms(errorCode); });
|
_updateTimer->async_wait([this](boost::system::error_code const& errorCode){ UpdateRealms(errorCode); });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user