fix
This commit is contained in:
63
src/main.cpp
Normal file
63
src/main.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
#include "character_creation_worker.h"
|
||||
#include "produce_worker.h"
|
||||
#include "connection_pool.h"
|
||||
#include "websocket_server.h"
|
||||
#include "message_broker.h"
|
||||
#include "config.h"
|
||||
#include <csignal>
|
||||
#include <atomic>
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
std::atomic<bool> keepRunning(true);
|
||||
|
||||
void handleSignal(int signal) {
|
||||
if (signal == SIGINT || signal == SIGTERM) {
|
||||
std::cerr << "Signal erhalten: " << signal << ". Beende Anwendung..." << std::endl;
|
||||
keepRunning.store(false, std::memory_order_relaxed);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::signal(SIGINT, handleSignal);
|
||||
std::signal(SIGTERM, handleSignal);
|
||||
|
||||
try {
|
||||
Config config("/etc/yourpart/daemon.conf");
|
||||
ConnectionPool pool(
|
||||
config.get("DB_HOST"),
|
||||
config.get("DB_PORT"),
|
||||
config.get("DB_NAME"),
|
||||
config.get("DB_USER"),
|
||||
config.get("DB_PASSWORD"),
|
||||
10
|
||||
);
|
||||
|
||||
int websocketPort = std::stoi(config.get("WEBSOCKET_PORT"));
|
||||
MessageBroker broker;
|
||||
WebSocketServer websocketServer(websocketPort, pool, broker);
|
||||
CharacterCreationWorker creationWorker(pool, broker);
|
||||
ProduceWorker produceWorker(pool, broker);
|
||||
|
||||
broker.start();
|
||||
websocketServer.run();
|
||||
creationWorker.startWorkerThread();
|
||||
produceWorker.startWorkerThread();
|
||||
creationWorker.enableWatchdog();
|
||||
produceWorker.enableWatchdog();
|
||||
|
||||
while (keepRunning) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
}
|
||||
|
||||
creationWorker.stopWorkerThread();
|
||||
produceWorker.stopWorkerThread();
|
||||
websocketServer.stop();
|
||||
broker.stop();
|
||||
} catch (const std::exception &e) {
|
||||
std::cerr << "Fehler: " << e.what() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user