From 4584390edc9b6f3d7b49ca25a49524a5fce4bfea Mon Sep 17 00:00:00 2001
From: vansangpfiev <vansangpfiev@gmail.com>
Date: Thu, 29 Aug 2024 15:36:07 +0700
Subject: [PATCH] fix: handle stop server

---
 engine/commands/run_cmd.cc           |  1 -
 engine/controllers/processManager.cc | 16 +++++++++++-----
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/engine/commands/run_cmd.cc b/engine/commands/run_cmd.cc
index 1c7e5c7e6..a84393652 100644
--- a/engine/commands/run_cmd.cc
+++ b/engine/commands/run_cmd.cc
@@ -70,7 +70,6 @@ bool RunCmd::IsModelExisted(const std::string& model_id) {
         try {
           config::YamlHandler handler;
           handler.ModelConfigFromFile(entry.path().string());
-          std::cout << entry.path().stem().string() << std::endl;
           if (entry.path().stem().string() == model_id) {
             return true;
           }
diff --git a/engine/controllers/processManager.cc b/engine/controllers/processManager.cc
index 2874a3860..15c213453 100644
--- a/engine/controllers/processManager.cc
+++ b/engine/controllers/processManager.cc
@@ -1,11 +1,17 @@
 #include "processManager.h"
-#include <cstdlib>
+#include "utils/cortex_utils.h"
+
 #include <trantor/utils/Logger.h>
+#include <cstdlib>
 
 void processManager::destroy(
-    const HttpRequestPtr &req,
-    std::function<void(const HttpResponsePtr &)> &&callback) {
+    const HttpRequestPtr& req,
+    std::function<void(const HttpResponsePtr&)>&& callback) {
+  app().quit();
+  Json::Value ret;
+  ret["message"] = "Program is exitting, goodbye!";
+  auto resp = cortex_utils::CreateCortexHttpJsonResponse(ret);
+  resp->setStatusCode(k200OK);
+  callback(resp);
   LOG_INFO << "Program is exitting, goodbye!";
-  exit(0);
-  return;
 };