- Refactoring Defines

- Moving de/serialization routines to a separate header
This commit is contained in:
Ian Roddis
2021-08-08 13:13:32 -03:00
parent 1849a2fee4
commit 7cd9fc5e6e
4 changed files with 48 additions and 18 deletions

View File

@@ -3,12 +3,12 @@
#include <chrono>
#include <string>
namespace daggy {
using Clock = std::chrono::system_clock;
#include "Defines.hpp"
namespace daggy {
struct AttemptRecord {
std::chrono::time_point<Clock> startTime;
std::chrono::time_point<Clock> stopTime;
TimePoint startTime;
TimePoint stopTime;
int rc; // RC from the task
std::string metaLog; // Logs from the executor
std::string output; // stdout from command

View File

@@ -0,0 +1,21 @@
#pragma once
#include <string>
#include <vector>
#include <unordered_map>
#include <variant>
namespace daggy {
// Commands and parameters
using ParameterValue = std::variant<std::string, std::vector<std::string>>;
using ParameterValues = std::unordered_map<std::string, ParameterValue>;
using Command = std::vector<std::string>;
// Time
using Clock = std::chrono::system_clock;
using TimePoint = std::chrono::time_point<Clock>;
// DAG Runs
using DAGDefID = int16_t;
using DAGRunID = size_t;
}

View File

@@ -0,0 +1,22 @@
#pragma once
#include <vector>
#include <string>
#include <variant>
#include <unordered_map>
#include <rapidjson/document.h>
#include "Logger.hpp"
#include "TaskExecutor.hpp"
#include "Task.hpp"
namespace rj = rapidjson;
namespace daggy {
ParameterValues parseParameters(const std::string & jsonSpec);
ParameterValues parseParameters(const rj::Document & spec);
std::vector<Task> buildTasks(const std::string & jsonSpec, const ParameterValues & parameters = {});
std::vector<Task> buildTasks(const rj::Document & spec, const ParameterValues & parameters = {});
std::vector<Command> expandCommands(const std::vector<std::string> & command, const ParameterValues & parameters);
}

View File

@@ -10,22 +10,9 @@
#include "Logger.hpp"
#include "TaskExecutor.hpp"
#include "Task.hpp"
#include "ThreadPool.hpp"
namespace rj = rapidjson;
#include "Defines.hpp"
namespace daggy {
using ParameterValue = std::variant<std::string, std::vector<std::string>>;
using ParameterValues = std::unordered_map<std::string, ParameterValue>;
using Command = std::vector<std::string>;
// Dealing with JSON
ParameterValues parseParameters(const std::string & jsonSpec);
ParameterValues parseParameters(const rj::Document & spec);
std::vector<Task> buildTasks(const std::string & jsonSpec, const ParameterValues & parameters = {});
std::vector<Task> buildTasks(const rj::Document & spec, const ParameterValues & parameters = {});
std::vector<Command> expandCommands(const std::vector<std::string> & command, const ParameterValues & parameters);
// DAG execution
// DAG vertex IDs should correspond to the position of tasks in vector. e.g. Vertex ID 0 corresponds to tasks[0]
// I'm not crazy about this loose coupling, but