Renaming rest_server to daggyd, and daggy to libdaggy

This commit is contained in:
Ian Roddis
2021-08-31 17:04:03 -03:00
parent 7b07380e16
commit 441cdb5b2e
6 changed files with 71 additions and 56 deletions

66
utils/daggyd/daggyd.cpp Normal file
View File

@@ -0,0 +1,66 @@
#include <iostream>
#include <fstream>
#include <argparse.hpp>
#include <daggy/Server.hpp>
// Add executors here
#include <daggy/executors/task/ForkingTaskExecutor.hpp>
// Add loggers here
#include <daggy/loggers/dag_run/OStreamLogger.hpp>
int main(int argc, char **argv) {
argparse::ArgumentParser args("Daggy");
args.add_argument("-v", "--verbose")
.default_value(false)
.implicit_value(true);
args.add_argument("-d", "--daemon")
.default_value(false)
.implicit_value(true);
args.add_argument("--ip")
.help("IP address to listen to")
.default_value("localhost");
args.add_argument("--log-file")
.help("File to log to.")
.default_value("daggyd.log");
args.add_argument("--port")
.help("Port to listen to")
.default_value(2503)
.action([](const std::string &value) { return std::stoi(value); });
args.add_argument("--dag-threads")
.help("Number of DAGs to run concurrently")
.default_value(10)
.action([](const std::string &value) { return std::stoull(value); });
args.add_argument("--web-threads")
.help("Number of web requests to support concurrently")
.default_value(30)
.action([](const std::string &value) { return std::stoull(value); });
args.add_argument("--executor-threads")
.help("Number of tasks to run concurrently")
.default_value(30)
.action([](const std::string &value) { return std::stoull(value); });
try {
args.parse_args(argc, argv);
} catch (std::exception &e) {
std::cout << "Error: " << e.what() << std::endl;
std::cout << args;
exit(1);
}
std::ofstream logFile(args.get<std::string>("--log-file"), std::ios::app);
daggy::loggers::dag_run::OStreamLogger logger(logFile);
daggy::executors::task::ForkingTaskExecutor executor(args.get<size_t>("--executor-threads"));
Pistache::Address listenSpec(args.get<std::string>("--ip"), args.get<uint16_t>("--port"));
daggy::Server server(listenSpec, logger, executor, args.get<size_t>("--dag-threads"));
server.init(args.get<size_t>("--web-threads"));
server.start();
std::cout << "Server running at http://localhost:2503, Ctrl-C to exit" << std::endl;
while (true) {
std::this_thread::sleep_for(std::chrono::seconds(30));
}
}