diff options
author | Kitzunu <24550914+Kitzunu@users.noreply.github.com> | 2024-12-22 09:42:39 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-22 09:42:39 +0100 |
commit | 7714ca31a253981d354a452001cca4d3792ab2f5 (patch) | |
tree | b2cd54bcce5933dcaf7fc40699b9288260cac91f /src/common | |
parent | 1462d1ae39e4b68e934ae32527cb47d57cb5ce68 (diff) |
refactor(Core/Time): Introduce GetExpirationTime instead of calculati⦠(#21006)
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/Asio/SteadyTimer.h | 31 | ||||
-rw-r--r-- | src/common/Metric/Metric.cpp | 9 |
2 files changed, 34 insertions, 6 deletions
diff --git a/src/common/Asio/SteadyTimer.h b/src/common/Asio/SteadyTimer.h new file mode 100644 index 0000000000..2c5a6fd7fa --- /dev/null +++ b/src/common/Asio/SteadyTimer.h @@ -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 diff --git a/src/common/Metric/Metric.cpp b/src/common/Metric/Metric.cpp index a6cd4b1f27..7c4771dcad 100644 --- a/src/common/Metric/Metric.cpp +++ b/src/common/Metric/Metric.cpp @@ -18,6 +18,7 @@ #include "Metric.h" #include "Config.h" #include "Log.h" +#include "SteadyTimer.h" #include "Strand.h" #include "Tokenize.h" #include <boost/algorithm/string/replace.hpp> @@ -246,9 +247,7 @@ void Metric::ScheduleSend() { if (_enabled) { - // Calculate the expiration time - auto expirationTime = std::chrono::steady_clock::now() + std::chrono::seconds(_updateInterval); - _batchTimer->expires_at(expirationTime); + _batchTimer->expires_at(Acore::Asio::SteadyTimer::GetExpirationTime(_updateInterval)); _batchTimer->async_wait(std::bind(&Metric::SendBatch, this)); } else @@ -281,9 +280,7 @@ void Metric::ScheduleOverallStatusLog() { if (_enabled) { - // Calculate the expiration time _overallStatusTimerInterval from now - auto expirationTime = std::chrono::steady_clock::now() + std::chrono::seconds(_overallStatusTimerInterval); - _overallStatusTimer->expires_at(expirationTime); + _overallStatusTimer->expires_at(Acore::Asio::SteadyTimer::GetExpirationTime(_overallStatusTimerInterval)); _overallStatusTimer->async_wait([this](const boost::system::error_code&) { _overallStatusTimerTriggered = true; |