(>10kb). Squashed commit of the following: commit b87fa418b4aca78928186a8fa992bef701e044a4 Author: Ian Roddis <tech@kinesin.ca> Date: Mon Feb 14 12:55:34 2022 -0400 removing memory leak commit 5e284ab92dbea991262a08c0cd50d6fc2f912e3b Author: Ian Roddis <tech@kinesin.ca> Date: Mon Feb 14 11:58:57 2022 -0400 Speeding up serialization, fixing payload sizing issue on daggyr commit e5e358820da4c2587741abdc3b6b103e5a4d4dd3 Author: Ian Roddis <tech@kinesin.ca> Date: Sun Feb 13 22:24:04 2022 -0400 changing newlines to std::endl for flush goodness commit 705ec86b75be947e64f4124ec8017cba2c8465e6 Author: Ian Roddis <tech@kinesin.ca> Date: Sun Feb 13 22:16:56 2022 -0400 adding more logging commit aa3db9c23e55da7a0523dc57e268b605ce8faac3 Author: Ian Roddis <tech@kinesin.ca> Date: Sun Feb 13 22:13:56 2022 -0400 Adding threadid commit 3b1a0f1333b2d43bc5ecad0746435504babbaa61 Author: Ian Roddis <tech@kinesin.ca> Date: Sun Feb 13 22:13:24 2022 -0400 Adding some debugging commit 804507e65251858fa597b7c27bcece8d8dfd589d Author: Ian Roddis <tech@kinesin.ca> Date: Sun Feb 13 21:52:53 2022 -0400 Removing curl global cleanup
77 lines
2.0 KiB
C++
77 lines
2.0 KiB
C++
#pragma once
|
|
|
|
#include <pistache/description.h>
|
|
#include <pistache/endpoint.h>
|
|
#include <pistache/http.h>
|
|
|
|
#include <daggy/DAGRunner.hpp>
|
|
#include <daggy/GeneralLogger.hpp>
|
|
#include <daggy/ThreadPool.hpp>
|
|
#include <daggy/executors/task/DaggyRunnerTaskExecutor.hpp>
|
|
#include <daggy/executors/task/ForkingTaskExecutor.hpp>
|
|
#include <daggy/loggers/dag_run/DAGRunLogger.hpp>
|
|
#include <deque>
|
|
#include <filesystem>
|
|
|
|
#define DAGGY_REST_HANDLER(func) \
|
|
void func(const Pistache::Rest::Request &request, \
|
|
Pistache::Http::ResponseWriter response);
|
|
|
|
namespace fs = std::filesystem;
|
|
using namespace daggy::executors::task::daggy_runner;
|
|
|
|
namespace daggy::daggyr {
|
|
|
|
class Server
|
|
{
|
|
public:
|
|
Server(const Pistache::Address &listenSpec, ssize_t maxCores,
|
|
ssize_t maxMemoryMB, GeneralLogger &logger);
|
|
~Server();
|
|
|
|
Server &setSSLCertificates(const fs::path &cert, const fs::path &key);
|
|
|
|
void init(size_t threads = 1);
|
|
|
|
void start();
|
|
|
|
uint16_t getPort() const;
|
|
|
|
void shutdown();
|
|
|
|
static void validateTask(const Task &task);
|
|
|
|
private:
|
|
void createDescription();
|
|
void serializeResults();
|
|
|
|
bool handleAuth(const Pistache::Rest::Request &request);
|
|
|
|
DAGGY_REST_HANDLER(handleReady);
|
|
DAGGY_REST_HANDLER(handleGetCapacity);
|
|
DAGGY_REST_HANDLER(handleRunTask);
|
|
DAGGY_REST_HANDLER(handlePollTask);
|
|
DAGGY_REST_HANDLER(handleStopTask);
|
|
DAGGY_REST_HANDLER(handleValidateTask);
|
|
|
|
Pistache::Http::Endpoint endpoint_;
|
|
Pistache::Rest::Description desc_;
|
|
Pistache::Rest::Router router_;
|
|
|
|
GeneralLogger &logger_;
|
|
executors::task::ForkingTaskExecutor executor_;
|
|
std::thread serializer_;
|
|
std::atomic<bool> running_;
|
|
|
|
using TaskID = std::pair<DAGRunID, std::string>;
|
|
Capacity maxCapacity_;
|
|
std::mutex rtGuard_;
|
|
std::unordered_map<TaskID, daggy::executors::task::TaskFuture>
|
|
runningTasks_;
|
|
|
|
std::mutex resultsGuard_;
|
|
std::unordered_map<TaskID, Future<std::string>>
|
|
results_;
|
|
};
|
|
} // namespace daggy::daggyr
|