stabilized app

This commit is contained in:
Torsten Schulz
2025-07-21 14:59:43 +02:00
committed by Torsten (PC)
parent 51fd9fcd13
commit 1451225978
25 changed files with 3590 additions and 228 deletions

View File

@@ -1,13 +1,21 @@
#include "character_creation_worker.h"
#include "produce_worker.h"
#include "stockagemanager.h"
#include "director_worker.h"
#include "valuerecalculationworker.h"
#include "connection_pool.h"
#include "websocket_server.h"
#include "message_broker.h"
#include "usercharacterworker.h"
#include "houseworker.h"
#include "politics_worker.h"
#include "config.h"
#include <csignal>
#include <atomic>
#include <iostream>
#include <thread>
#include <vector>
#include <memory>
std::atomic<bool> keepRunning(true);
@@ -25,39 +33,44 @@ int main() {
try {
Config config("/etc/yourpart/daemon.conf");
ConnectionPool pool(
config.get("DB_HOST"),
config.get("DB_PORT"),
config.get("DB_HOST"),
config.get("DB_PORT"),
config.get("DB_NAME"),
config.get("DB_USER"),
config.get("DB_PASSWORD"),
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);
std::vector<std::unique_ptr<Worker>> workers;
workers.push_back(std::make_unique<CharacterCreationWorker>(pool, broker));
workers.push_back(std::make_unique<ProduceWorker>(pool, broker));
workers.push_back(std::make_unique<StockageManager>(pool, broker));
workers.push_back(std::make_unique<DirectorWorker>(pool, broker));
workers.push_back(std::make_unique<ValueRecalculationWorker>(pool, broker));
workers.push_back(std::make_unique<UserCharacterWorker>(pool, broker));
workers.push_back(std::make_unique<HouseWorker>(pool, broker));
workers.push_back(std::make_unique<PoliticsWorker>(pool, broker));
websocketServer.setWorkers(workers);
broker.start();
websocketServer.run();
creationWorker.startWorkerThread();
produceWorker.startWorkerThread();
creationWorker.enableWatchdog();
produceWorker.enableWatchdog();
for (auto &worker : workers) {
worker->startWorkerThread();
worker->enableWatchdog();
}
while (keepRunning) {
std::this_thread::sleep_for(std::chrono::milliseconds(500));
}
creationWorker.stopWorkerThread();
produceWorker.stopWorkerThread();
for (auto &worker : workers) {
worker->stopWorkerThread();
}
websocketServer.stop();
broker.stop();
} catch (const std::exception &e) {
std::cerr << "Fehler: " << e.what() << std::endl;
return 1;
}
return 0;
}