Converting to better_enums to support gcc 8
This commit is contained in:
@@ -10,7 +10,7 @@ find_package(Threads REQUIRED)
|
||||
|
||||
include(cmake/rapidjson.cmake)
|
||||
include(cmake/pistache.cmake)
|
||||
include(cmake/MagicEnum.cmake)
|
||||
include(cmake/better-enums.cmake)
|
||||
include(cmake/argparse.cmake)
|
||||
include(cmake/Catch2.cmake)
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ Building
|
||||
|
||||
- git
|
||||
- cmake >= 3.14
|
||||
- gcc >= 9
|
||||
- gcc >= 8
|
||||
|
||||
```
|
||||
git clone https://gitlab.com/iroddis/daggy
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
include(ExternalProject)
|
||||
|
||||
project(magicEnum)
|
||||
project(better-enums)
|
||||
|
||||
ExternalProject_Add(${PROJECT_NAME}-external
|
||||
GIT_REPOSITORY https://github.com/Neargye/magic_enum.git
|
||||
GIT_TAG "v0.7.3"
|
||||
GIT_REPOSITORY https://github.com/aantron/better-enums.git
|
||||
GIT_TAG "0.11.3"
|
||||
GIT_SHALLOW TRUE
|
||||
SOURCE_DIR ${THIRD_PARTY_DIR}/${PROJECT_NAME}
|
||||
BUILD_COMMAND ""
|
||||
@@ -12,4 +12,4 @@ ExternalProject_Add(${PROJECT_NAME}-external
|
||||
CONFIGURE_COMMAND "")
|
||||
add_library(${PROJECT_NAME} INTERFACE)
|
||||
add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}-external)
|
||||
target_include_directories(${PROJECT_NAME} SYSTEM INTERFACE ${THIRD_PARTY_DIR}/${PROJECT_NAME}/include)
|
||||
target_include_directories(${PROJECT_NAME} SYSTEM INTERFACE ${THIRD_PARTY_DIR}/${PROJECT_NAME})
|
||||
@@ -3,4 +3,4 @@ project(daggy)
|
||||
file(GLOB_RECURSE SOURCES src/*.cpp)
|
||||
add_library(${PROJECT_NAME} STATIC ${SOURCES})
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC include)
|
||||
target_link_libraries(${PROJECT_NAME} pistache pthread rapidjson magicEnum)
|
||||
target_link_libraries(${PROJECT_NAME} pistache pthread rapidjson better-enums)
|
||||
@@ -7,6 +7,8 @@
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
#include <enum.h>
|
||||
|
||||
namespace daggy {
|
||||
// Commands and parameters
|
||||
using ParameterValue = std::variant<std::string, std::vector<std::string>>;
|
||||
@@ -18,18 +20,17 @@ namespace daggy {
|
||||
using TimePoint = std::chrono::time_point<Clock>;
|
||||
|
||||
// DAG Runs
|
||||
using DAGDefID = int16_t;
|
||||
using DAGRunID = size_t;
|
||||
using TaskID = size_t;
|
||||
|
||||
enum class RunState : uint32_t {
|
||||
QUEUED = 0,
|
||||
RUNNING = 1,
|
||||
RETRY = 1 << 1,
|
||||
ERRORED = 1 << 2,
|
||||
KILLED = 1 << 3,
|
||||
COMPLETED = 1 << 4
|
||||
};
|
||||
BETTER_ENUM(RunState, uint32_t,
|
||||
QUEUED = 1,
|
||||
RUNNING = 1 << 1,
|
||||
RETRY = 1 << 2,
|
||||
ERRORED = 1 << 3,
|
||||
KILLED = 1 << 4,
|
||||
COMPLETED = 1 << 5
|
||||
);
|
||||
|
||||
struct Task {
|
||||
std::string name;
|
||||
@@ -56,3 +57,5 @@ namespace daggy {
|
||||
std::string errorLog; // stderr from command
|
||||
};
|
||||
}
|
||||
|
||||
BETTER_ENUMS_DECLARE_STD_HASH(daggy::RunState)
|
||||
@@ -28,7 +28,7 @@ namespace daggy {
|
||||
bool DAG::hasPath(const size_t from, const size_t to) const {
|
||||
if (from >= vertices_.size()) throw std::runtime_error("No such vertex " + std::to_string(from));
|
||||
if (to >= vertices_.size()) throw std::runtime_error("No such vertex " + std::to_string(to));
|
||||
for (const auto &child : vertices_[from].children) {
|
||||
for (const auto &child: vertices_[from].children) {
|
||||
if (child == to) return true;
|
||||
if (hasPath(child, to)) return true;
|
||||
}
|
||||
@@ -38,22 +38,22 @@ namespace daggy {
|
||||
|
||||
void DAG::reset() {
|
||||
// Reset the state of all vertices
|
||||
for (auto &v : vertices_) {
|
||||
for (auto &v: vertices_) {
|
||||
v.state = RunState::QUEUED;
|
||||
v.depCount = 0;
|
||||
}
|
||||
|
||||
// Calculate the upstream count
|
||||
for (auto &v : vertices_) {
|
||||
for (auto c : v.children) {
|
||||
for (auto &v: vertices_) {
|
||||
for (auto c: v.children) {
|
||||
++vertices_[c].depCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DAG::resetRunning() {
|
||||
for (auto &v : vertices_) {
|
||||
if (v.state != RunState::RUNNING) continue;
|
||||
for (auto &v: vertices_) {
|
||||
if (v.state != +RunState::RUNNING) continue;
|
||||
v.state = RunState::QUEUED;
|
||||
}
|
||||
}
|
||||
@@ -63,8 +63,8 @@ namespace daggy {
|
||||
}
|
||||
|
||||
bool DAG::allVisited() const {
|
||||
for (const auto &v : vertices_) {
|
||||
if (v.state != RunState::COMPLETED) return false;
|
||||
for (const auto &v: vertices_) {
|
||||
if (v.state != +RunState::COMPLETED) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -73,7 +73,7 @@ namespace daggy {
|
||||
for (size_t i = 0; i < vertices_.size(); ++i) {
|
||||
auto &v = vertices_[i];
|
||||
|
||||
if (v.state != RunState::QUEUED) continue;
|
||||
if (v.state != +RunState::QUEUED) continue;
|
||||
if (v.depCount != 0) continue;
|
||||
v.state = RunState::RUNNING;
|
||||
return i;
|
||||
@@ -84,7 +84,7 @@ namespace daggy {
|
||||
void DAG::completeVisit(const size_t id) {
|
||||
auto &v = vertices_[id];
|
||||
v.state = RunState::COMPLETED;
|
||||
for (auto c : v.children) {
|
||||
for (auto c: v.children) {
|
||||
--vertices_[c].depCount;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#include <magic_enum.hpp>
|
||||
#include <iomanip>
|
||||
|
||||
#include <enum.h>
|
||||
|
||||
#include <daggy/Server.hpp>
|
||||
|
||||
#include <daggy/Serialization.hpp>
|
||||
#include <daggy/Utilities.hpp>
|
||||
|
||||
@@ -143,7 +144,7 @@ namespace daggy {
|
||||
ss << '[';
|
||||
|
||||
bool first = true;
|
||||
for (const auto &run : dagRuns) {
|
||||
for (const auto &run: dagRuns) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
@@ -157,13 +158,13 @@ namespace daggy {
|
||||
<< R"("lastUpdate": )" << std::quoted(timePointToString(run.lastUpdate)) << ','
|
||||
<< R"("taskCounts": {)";
|
||||
bool firstState = true;
|
||||
for (const auto &[state, count] : run.taskStateCounts) {
|
||||
for (const auto &[state, count]: run.taskStateCounts) {
|
||||
if (firstState) {
|
||||
firstState = false;
|
||||
} else {
|
||||
ss << ", ";
|
||||
}
|
||||
ss << std::quoted(magic_enum::enum_name(state)) << ':' << count;
|
||||
ss << std::quoted(state._to_string()) << ':' << count;
|
||||
}
|
||||
ss << '}' // end of taskCounts
|
||||
<< '}'; // end of item
|
||||
@@ -189,20 +190,20 @@ namespace daggy {
|
||||
// task run states
|
||||
ss << R"("taskStates": [ )";
|
||||
first = true;
|
||||
for (const auto &state : run.taskRunStates) {
|
||||
for (const auto &state: run.taskRunStates) {
|
||||
if (first) { first = false; } else { ss << ','; }
|
||||
ss << std::quoted(magic_enum::enum_name(state));
|
||||
ss << std::quoted(state._to_string());
|
||||
}
|
||||
ss << "],";
|
||||
|
||||
// Attempt records
|
||||
first = true;
|
||||
ss << R"("taskAttempts": [ )";
|
||||
for (const auto &attempts : run.taskAttempts) {
|
||||
for (const auto &attempts: run.taskAttempts) {
|
||||
if (first) { first = false; } else { ss << ','; }
|
||||
ss << '[';
|
||||
bool firstAttempt = true;
|
||||
for (const auto &attempt : attempts) {
|
||||
for (const auto &attempt: attempts) {
|
||||
if (firstAttempt) { firstAttempt = false; } else { ss << ','; }
|
||||
ss << '{'
|
||||
<< R"("startTime":)" << std::quoted(timePointToString(attempt.startTime)) << ','
|
||||
@@ -220,10 +221,10 @@ namespace daggy {
|
||||
// DAG state changes
|
||||
first = true;
|
||||
ss << R"("dagStateChanges": [ )";
|
||||
for (const auto &change : run.dagStateChanges) {
|
||||
for (const auto &change: run.dagStateChanges) {
|
||||
if (first) { first = false; } else { ss << ','; }
|
||||
ss << '{'
|
||||
<< R"("newState": )" << std::quoted(magic_enum::enum_name(change.newState)) << ','
|
||||
<< R"("newState": )" << std::quoted(change.newState._to_string()) << ','
|
||||
<< R"("time": )" << std::quoted(timePointToString(change.time))
|
||||
<< '}';
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
|
||||
#include <magic_enum.hpp>
|
||||
#include <enum.h>
|
||||
|
||||
#include <daggy/loggers/dag_run/FileSystemLogger.hpp>
|
||||
#include <daggy/Serialization.hpp>
|
||||
@@ -22,12 +23,12 @@ namespace daggy {
|
||||
FileSystemLogger::FileSystemLogger(fs::path root)
|
||||
: root_(root), nextRunID_(0) {
|
||||
const std::vector<fs::path> reqPaths{root_, getCurrentPath(), getRunsRoot()};
|
||||
for (const auto &path : reqPaths) {
|
||||
for (const auto &path: reqPaths) {
|
||||
if (!fs::exists(path)) { fs::create_directories(path); }
|
||||
}
|
||||
|
||||
// Get the next run ID
|
||||
for (auto &dir : fs::directory_iterator(getRunsRoot())) {
|
||||
for (auto &dir: fs::directory_iterator(getRunsRoot())) {
|
||||
try {
|
||||
size_t runID = std::stoull(dir.path().stem());
|
||||
if (runID > nextRunID_) nextRunID_ = runID + 1;
|
||||
@@ -55,7 +56,7 @@ namespace daggy {
|
||||
ofh.close();
|
||||
|
||||
// Task directories
|
||||
for (const auto &task : tasks) {
|
||||
for (const auto &task: tasks) {
|
||||
auto taskDir = runRoot / task.name;
|
||||
fs::create_directories(taskDir);
|
||||
std::ofstream ofh(taskDir / "states.csv");
|
||||
@@ -66,7 +67,7 @@ namespace daggy {
|
||||
|
||||
void FileSystemLogger::updateDAGRunState(DAGRunID dagRunID, RunState state) {
|
||||
std::ofstream ofh(getRunRoot(dagRunID) / "states.csv", std::ios::binary | std::ios::app);
|
||||
ofh << std::quoted(timePointToString(Clock::now())) << ',' << magic_enum::enum_name(state) << '\n';
|
||||
ofh << std::quoted(timePointToString(Clock::now())) << ',' << state._to_string() << '\n';
|
||||
ofh.flush();
|
||||
ofh.close();
|
||||
}
|
||||
@@ -109,7 +110,7 @@ namespace daggy {
|
||||
|
||||
void FileSystemLogger::updateTaskState(DAGRunID dagRunID, const std::string &taskName, RunState state) {
|
||||
std::ofstream ofh(getRunRoot(dagRunID) / taskName / "states.csv", std::ios::binary | std::ios::app);
|
||||
ofh << std::quoted(timePointToString(Clock::now())) << ',' << magic_enum::enum_name(state) << '\n';
|
||||
ofh << std::quoted(timePointToString(Clock::now())) << ',' << state._to_string() << '\n';
|
||||
ofh.flush();
|
||||
ofh.close();
|
||||
}
|
||||
@@ -151,13 +152,13 @@ namespace daggy {
|
||||
|
||||
record.dagStateChanges.emplace_back(DAGUpdateRecord{
|
||||
.time = stringToTimePoint(time),
|
||||
.newState = magic_enum::enum_cast<RunState>(state).value()
|
||||
.newState = RunState::_from_string(state.c_str())
|
||||
});
|
||||
}
|
||||
ifh.close();
|
||||
|
||||
// Task states
|
||||
for (const auto &task : record.tasks) {
|
||||
for (const auto &task: record.tasks) {
|
||||
auto taskStateFile = runRoot / task.name / "states.csv";
|
||||
if (!fs::exists(taskStateFile)) {
|
||||
record.taskRunStates.push_back(RunState::QUEUED);
|
||||
@@ -168,7 +169,7 @@ namespace daggy {
|
||||
while (std::getline(ifh, line)) { continue; }
|
||||
std::stringstream ss{line};
|
||||
while (std::getline(ss, token, ',')) { continue; }
|
||||
RunState taskState = magic_enum::enum_cast<RunState>(token).value();
|
||||
RunState taskState = RunState::_from_string(token.c_str());
|
||||
record.taskRunStates.emplace_back(taskState);
|
||||
ifh.close();
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <iterator>
|
||||
#include <algorithm>
|
||||
|
||||
#include <magic_enum.hpp>
|
||||
#include <enum.h>
|
||||
|
||||
#include <daggy/loggers/dag_run/OStreamLogger.hpp>
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace daggy {
|
||||
|
||||
os_ << "Starting new DAGRun named " << name << " with ID " << runID << " and " << tasks.size()
|
||||
<< " tasks" << std::endl;
|
||||
for (const auto &task : tasks) {
|
||||
for (const auto &task: tasks) {
|
||||
os_ << "TASK (" << task.name << "): ";
|
||||
std::copy(task.command.begin(), task.command.end(),
|
||||
std::ostream_iterator<std::string>(os_, " "));
|
||||
@@ -34,7 +34,7 @@ namespace daggy {
|
||||
|
||||
void OStreamLogger::updateDAGRunState(DAGRunID dagRunID, RunState state) {
|
||||
std::lock_guard<std::mutex> lock(guard_);
|
||||
os_ << "DAG State Change(" << dagRunID << "): " << magic_enum::enum_name(state) << std::endl;
|
||||
os_ << "DAG State Change(" << dagRunID << "): " << state._to_string() << std::endl;
|
||||
dagRuns_[dagRunID].dagStateChanges.push_back({Clock::now(), state});
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace daggy {
|
||||
dagRun.taskRunStates[taskID] = state;
|
||||
|
||||
os_ << "Task State Change (" << dagRunID << '/' << taskName << " [task_id: " << taskID << "]): "
|
||||
<< magic_enum::enum_name(state)
|
||||
<< state._to_string()
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace daggy {
|
||||
std::vector<DAGRunSummary> summaries;
|
||||
std::lock_guard<std::mutex> lock(guard_);
|
||||
size_t i = 0;
|
||||
for (const auto &run : dagRuns_) {
|
||||
for (const auto &run: dagRuns_) {
|
||||
DAGRunSummary summary{
|
||||
.runID = i,
|
||||
.name = run.name,
|
||||
@@ -84,12 +84,12 @@ namespace daggy {
|
||||
run.dagStateChanges.back().time)
|
||||
};
|
||||
|
||||
std::vector<RunState> states(run.tasks.size());
|
||||
for (const auto &taskUpdate : run.taskStateChanges) {
|
||||
std::vector<RunState> states(run.tasks.size(), RunState::QUEUED);
|
||||
for (const auto &taskUpdate: run.taskStateChanges) {
|
||||
states[taskUpdate.taskID] = taskUpdate.newState;
|
||||
}
|
||||
|
||||
for (const auto &taskState : states) {
|
||||
for (const auto &taskState: states) {
|
||||
summary.taskStateCounts[taskState]++;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user