From a5a989b359661e6d2ffd9220c23a7677dca5e0cc Mon Sep 17 00:00:00 2001 From: Fabian Posch Date: Tue, 9 Jan 2024 21:27:39 -0500 Subject: [PATCH] fixed task completeness was not checked before upload --- include/actsim_agent/worker.hpp | 2 +- src/actsim_agent/worker.cpp | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/include/actsim_agent/worker.hpp b/include/actsim_agent/worker.hpp index 693b589..0536202 100644 --- a/include/actsim_agent/worker.hpp +++ b/include/actsim_agent/worker.hpp @@ -46,7 +46,7 @@ class Worker { private: void thread_run(); - void perform_task(std::unique_ptr& task, bool& success); + bool perform_task(std::unique_ptr& task); std::unique_ptr worker_thread; std::atomic current_task; diff --git a/src/actsim_agent/worker.cpp b/src/actsim_agent/worker.cpp index 012ae03..fee3f65 100644 --- a/src/actsim_agent/worker.cpp +++ b/src/actsim_agent/worker.cpp @@ -60,17 +60,18 @@ void Worker::thread_run() { if (queue_empty) continue; // everything is good, perform the given task - bool success; - this->perform_task(task, success); + bool complete = this->perform_task(task); - // if everything worked, push the task to be uploaded - this->interface.push_finished(std::move(task)); + // if the task was finished, push the task to be uploaded + // we need this since the task might have been interrupted + // half way though + if (complete) this->interface.push_finished(std::move(task)); } } -void Worker::perform_task(std::unique_ptr& task, bool& success) { +bool Worker::perform_task(std::unique_ptr& task) { std::cout << "Worker ping" << std::endl; usleep(100000); - success = true; task->get_uuid(); + return true; }