From 127074f85e6c828f067d51ad6d70b465ebf8adc0 Mon Sep 17 00:00:00 2001 From: Fabian Posch Date: Fri, 3 Jan 2025 12:55:44 +0100 Subject: [PATCH] upload fault flags, streamline code --- include/actsim_agent/uploader.hpp | 2 + src/actsim_agent/uploader.cpp | 68 +++++++++++++++++++++++-------- 2 files changed, 53 insertions(+), 17 deletions(-) diff --git a/include/actsim_agent/uploader.hpp b/include/actsim_agent/uploader.hpp index ceef2c0..387fa1c 100644 --- a/include/actsim_agent/uploader.hpp +++ b/include/actsim_agent/uploader.hpp @@ -28,6 +28,7 @@ #include #include +#include #include #include "task_interface.hpp" @@ -44,6 +45,7 @@ class Uploader { void thread_run(); bool upload_task(std::unique_ptr task); + std::string build_fault_flags(const std::unique_ptr& task); std::unique_ptr uploader_thread; std::unique_ptr conn; diff --git a/src/actsim_agent/uploader.cpp b/src/actsim_agent/uploader.cpp index 1a0ec8b..cca35cb 100644 --- a/src/actsim_agent/uploader.cpp +++ b/src/actsim_agent/uploader.cpp @@ -23,9 +23,12 @@ ************************************************************************** */ +#include #include #include #include +#include +#include "task_interface.hpp" #include "util.h" #include "uploader.hpp" @@ -60,7 +63,7 @@ void Uploader::thread_run() { // program was halted this->interface.wait_for_finished(); - DEBUG_PRINT("Uploader was worken up"); + DEBUG_PRINT("Uploader was woken up"); // so first we check if we should still be running if (!this->interface.running()) break; @@ -117,29 +120,60 @@ void Uploader::thread_run() { bool Uploader::upload_task(std::unique_ptr task) { + auto&& task_id = task->id; + auto&& sim_log = task->get_content().first; + auto&& sim_error = task->get_content().second; + auto&& output_tokens = task->output_tokens; + + const auto&& fault_flags = build_fault_flags(task); + // make sure any task that is uploaded isn't halted in the database - auto task_upload_lambda = []( - pqxx::work *txn, - const db::uuid_t *target, - std::vector *sim_log, - std::vector *sim_error + auto task_upload_lambda = [task_id, sim_log, sim_error, output_tokens, fault_flags]( + pqxx::work *txn ) { txn->exec_params0( - "UPDATE sim_outputs SET sim_log = $1, error_log = $2, part_status = 'finished' WHERE id = $3 AND part_status != 'halted';", - *sim_log, - *sim_error, - *target + "UPDATE sim_outputs SET " + " sim_log = $1, " + " error_log = $2, " + " output_tokens = $3, " + " fault_flags = $4, " + " part_status = 'finished' " + "WHERE id = $5 AND part_status != 'halted';", + sim_log, + sim_error, + output_tokens, + fault_flags, + task_id ); }; - std::function*, - std::vector* - )> task_upload_func = task_upload_lambda; + std::function task_upload_func = task_upload_lambda; DEBUG_PRINT("Updating task " + db::to_string(task->id)); - return this->conn->send_request(&task_upload_func, &(task->id), &(task->get_content().first), &(task->get_content().second)); + return this->conn->send_request(&task_upload_func); +} + +std::string Uploader::build_fault_flags(const std::unique_ptr& task) { + + // bit mask for faults is + // 0: timing + // 1: value + // 2: coding + // 3: glitch + // 4: deadlock + // 5: token count + // 54 3210 + // XX XXXX + + std::stringstream flags; + + flags << (task->fault_token_count ? "1" : "0"); + flags << (task->fault_deadlock ? "1" : "0"); + flags << (task->fault_glitch ? "1" : "0"); + flags << (task->fault_coding ? "1" : "0"); + flags << (task->fault_value ? "1" : "0"); + flags << (task->fault_timing_deviation ? "1" : "0"); + + return flags.str(); }