Multiple implementations of the same back-end application. The aim is to provide quick, side-by-side comparisons of different technologies (languages, frameworks, libraries) while preserving consistent business logic across all implementations.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

71 lines
1.5 KiB

#include "App.h"
#include "SpdLogger.h"
#include "OsHelpers.h"
#include <iostream>
#include <filesystem>
namespace nxl {
using nxl::autostore::AutoStore;
std::condition_variable App::exitCv;
std::mutex App::mtx;
bool App::shouldExit = false;
nxl::autostore::ILoggerPtr log{nullptr};
App::App(int argc, char** argv)
{
signal(SIGINT, App::handleSignal);
signal(SIGTERM, App::handleSignal);
auto spdLogger = spdlog::stdout_color_mt("console");
spdLogger->set_pattern("[%Y-%m-%d %H:%M:%S] [%^%l%$] %v");
spdLogger->set_level(spdlog::level::debug);
log = logger = std::make_shared<SpdLogger>(spdLogger, 9);
autoStore = std::make_unique<AutoStore>(
AutoStore::Config{
.dataPath = os::getApplicationDirectory() + "/data",
.host = "0.0.0.0",
.port = 8080,
},
logger);
if (!autoStore->initialize()) {
std::cerr << "Failed to initialize AutoStore" << std::endl;
throw std::runtime_error("Failed to initialize AutoStore");
}
}
App::~App() = default;
int App::exec()
{
if (!autoStore->start()) {
std::cerr << "Failed to start AutoStore services" << std::endl;
return 1;
}
logger->info("AutoStore is running. Press Ctrl+C to stop.");
std::unique_lock<std::mutex> lock(mtx);
exitCv.wait(lock, [] { return shouldExit; });
autoStore->stop();
return 0;
}
void App::handleSignal(int signum)
{
if (log) {
log->info("Caught signal %d. Graceful shutdown.", signum);
}
{
std::lock_guard<std::mutex> lock(mtx);
shouldExit = true;
}
exitCv.notify_one();
}
} // namespace nxl