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; }