chức năng dashboard
This commit is contained in:
@@ -93,6 +93,8 @@ void MissionQueue::ensureRunnerDefaults()
|
||||
runner_["current_queue_id"] = nullptr;
|
||||
if (!runner_.contains("current_action"))
|
||||
runner_["current_action"] = nullptr;
|
||||
if (!runner_.contains("paused"))
|
||||
runner_["paused"] = false;
|
||||
}
|
||||
|
||||
void MissionQueue::startWorkerIfNeeded()
|
||||
@@ -255,6 +257,43 @@ bool MissionQueue::reorder(const nlohmann::json& ordered_ids, std::string& err)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MissionQueue::pause(std::string& err)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mu_);
|
||||
const std::string state = runner_.value("state", "idle");
|
||||
if (state != "running")
|
||||
{
|
||||
err = "no mission is running";
|
||||
return false;
|
||||
}
|
||||
paused_ = true;
|
||||
runner_["paused"] = true;
|
||||
runner_["state"] = "paused";
|
||||
runner_["message"] = "Mission tạm dừng";
|
||||
runner_["updated_at"] = IdUtil::nowIso8601();
|
||||
saveUnlocked();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MissionQueue::resume(std::string& err)
|
||||
{
|
||||
(void)err;
|
||||
paused_ = false;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mu_);
|
||||
runner_["paused"] = false;
|
||||
if (runner_.value("state", "") == "paused")
|
||||
{
|
||||
runner_["state"] = "running";
|
||||
runner_["message"] = "Tiếp tục mission";
|
||||
runner_["updated_at"] = IdUtil::nowIso8601();
|
||||
}
|
||||
saveUnlocked();
|
||||
}
|
||||
wake_ = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void MissionQueue::workerLoop()
|
||||
{
|
||||
while (!stop_)
|
||||
@@ -273,6 +312,8 @@ void MissionQueue::processQueueUnlocked()
|
||||
{
|
||||
if (!queue_.is_array())
|
||||
return;
|
||||
if (paused_)
|
||||
return;
|
||||
|
||||
for (auto& item : queue_)
|
||||
{
|
||||
@@ -335,6 +376,10 @@ void MissionQueue::executeActionsUnlocked(const nlohmann::json& actions,
|
||||
{
|
||||
if (!action.is_object())
|
||||
continue;
|
||||
while (paused_ && !stop_)
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
if (stop_)
|
||||
return;
|
||||
|
||||
const std::string action_id = action.value("id", "");
|
||||
const std::string kind = action.value("kind", "action");
|
||||
@@ -433,7 +478,11 @@ void MissionQueue::sleepMs(int ms)
|
||||
return;
|
||||
const int step = 100;
|
||||
for (int elapsed = 0; elapsed < ms && !stop_; elapsed += step)
|
||||
{
|
||||
while (paused_ && !stop_)
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(std::min(step, ms - elapsed)));
|
||||
}
|
||||
}
|
||||
|
||||
void MissionQueue::setRunnerState(const std::string& state, const std::string& message)
|
||||
|
||||
Reference in New Issue
Block a user