GracefullyShutdown: Add "subsystem x/y shutting down" message

Remove old "X shutting down", "X shut down" messages, they were bad and
confusing
This commit is contained in:
Lion Kortlepel 2021-09-09 11:58:58 +03:00 committed by Lion
parent d43ee4b7b6
commit b055fd8bda
6 changed files with 14 additions and 14 deletions

View File

@ -22,11 +22,20 @@ void Application::RegisterShutdownHandler(const TShutdownHandler& Handler) {
} }
} }
static bool AlreadyShuttingDown = false;
void Application::GracefullyShutdown() { void Application::GracefullyShutdown() {
info("please wait while all subsystems are shutting down..."); if (AlreadyShuttingDown) {
info("already shutting down");
return;
} else {
AlreadyShuttingDown = true;
}
trace("waiting for lock release");
std::unique_lock Lock(mShutdownHandlersMutex); std::unique_lock Lock(mShutdownHandlersMutex);
for (auto& Handler : mShutdownHandlers) { info("please wait while all subsystems are shutting down...");
Handler(); for (size_t i = 0; i < mShutdownHandlers.size(); ++i) {
info("Subsystem " + std::to_string(i + 1) + "/" + std::to_string(mShutdownHandlers.size()) + " shutting down");
mShutdownHandlers[i]();
} }
} }

View File

@ -107,10 +107,8 @@ THeartbeatThread::THeartbeatThread(TResourceManager& ResourceManager, TServer& S
, mServer(Server) { , mServer(Server) {
Application::RegisterShutdownHandler([&] { Application::RegisterShutdownHandler([&] {
if (mThread.joinable()) { if (mThread.joinable()) {
debug("shutting down Heartbeat");
mShutdown = true; mShutdown = true;
mThread.join(); mThread.join();
debug("shut down Heartbeat");
} }
}); });
Start(); Start();

View File

@ -23,10 +23,8 @@ TLuaEngine::TLuaEngine(TServer& Server, TNetwork& Network)
FolderList(Path, false); FolderList(Path, false);
mPath = Path; mPath = Path;
Application::RegisterShutdownHandler([&] {if (mThread.joinable()) { Application::RegisterShutdownHandler([&] {if (mThread.joinable()) {
debug("shutting down LuaEngine");
mShutdown = true; mShutdown = true;
mThread.join(); mThread.join();
debug("shut down LuaEngine");
} }); } });
Start(); Start();
} }

View File

@ -20,18 +20,14 @@ TNetwork::TNetwork(TServer& Server, TPPSMonitor& PPSMonitor, TResourceManager& R
}); });
Application::RegisterShutdownHandler([&] { Application::RegisterShutdownHandler([&] {
if (mUDPThread.joinable()) { if (mUDPThread.joinable()) {
debug("shutting down TCPServer");
mShutdown = true; mShutdown = true;
mUDPThread.detach(); mUDPThread.detach();
debug("shut down TCPServer");
} }
}); });
Application::RegisterShutdownHandler([&] { Application::RegisterShutdownHandler([&] {
if (mTCPThread.joinable()) { if (mTCPThread.joinable()) {
debug("shutting down TCPServer");
mShutdown = true; mShutdown = true;
mTCPThread.detach(); mTCPThread.detach();
debug("shut down TCPServer");
} }
}); });
mTCPThread = std::thread(&TNetwork::TCPServerMain, this); mTCPThread = std::thread(&TNetwork::TCPServerMain, this);

View File

@ -7,10 +7,8 @@ TPPSMonitor::TPPSMonitor(TServer& Server)
Application::SetPPS("-"); Application::SetPPS("-");
Application::RegisterShutdownHandler([&] { Application::RegisterShutdownHandler([&] {
if (mThread.joinable()) { if (mThread.joinable()) {
debug("shutting down PPSMonitor");
mShutdown = true; mShutdown = true;
mThread.join(); mThread.join();
debug("shut down PPSMonitor");
} }
}); });
Start(); Start();

View File

@ -56,8 +56,9 @@ int main(int argc, char** argv) try {
// TODO: replace // TODO: replace
while (!Shutdown) { while (!Shutdown) {
std::this_thread::sleep_for(std::chrono::milliseconds(100)); std::this_thread::sleep_for(std::chrono::milliseconds(50));
} }
info("Shutdown.");
} catch (const std::exception& e) { } catch (const std::exception& e) {
error(e.what()); error(e.what());
Sentry.LogException(e, _file_basename, _line); Sentry.LogException(e, _file_basename, _line);