- Adding default pretty-printer for Task

- Adding equivalency check for Task
- Adding test to ensure serialization / deserialization is reproducible.
This commit is contained in:
Ian Roddis
2021-08-11 10:16:38 -03:00
parent a152588368
commit 4d519cc596
4 changed files with 32 additions and 4 deletions

View File

@@ -26,4 +26,7 @@ namespace daggy {
std::string taskToJSON(const Task &task);
std::string tasksToJSON(const std::vector<Task> &tasks);
// default serialization
std::ostream &operator<<(std::ostream &os, const Task &task);
}

View File

@@ -12,5 +12,13 @@ namespace daggy {
uint32_t maxRetries;
uint32_t retryIntervalSeconds; // Time to wait between retries
std::unordered_set<std::string> children;
bool operator==(const Task &other) const {
return (name == other.name)
and (maxRetries == other.maxRetries)
and (retryIntervalSeconds == other.retryIntervalSeconds)
and (command == other.command)
and (children == other.children);
}
};
}

View File

@@ -111,10 +111,10 @@ namespace daggy {
// Create the tasks
auto &taskNames = childrenMap[name];
for (size_t tid = 0; tid < commands.size(); ++tid) {
std::string taskName = name + "_" + std::to_string(tid);
std::string taskName = (commands.size() == 1 ? name : name + "_" + std::to_string(tid));
taskNames.push_back(taskName);
tasks.emplace_back(Task{
.name = name + "_" + std::to_string(tid),
.name = taskName,
.command = commands[tid],
.maxRetries = maxRetries,
.retryIntervalSeconds = retryIntervalSeconds,
@@ -195,4 +195,9 @@ namespace daggy {
return ss.str();
}
std::ostream &operator<<(std::ostream &os, const Task &task) {
os << taskToJSON(task);
return os;
}
}