Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit afe556d

Browse files
authored
Merge pull request #1705 from janhq/j/add-file-watcher
feat: add file watcher service
2 parents f5c3b02 + e77d439 commit afe556d

File tree

8 files changed

+396
-6
lines changed

8 files changed

+396
-6
lines changed

engine/cli/commands/engine_install_cmd.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,6 @@ bool EngineInstallCmd::Exec(const std::string& engine,
183183
return false;
184184
}
185185

186-
CLI_LOG("Validating download items, please wait..")
187-
188186
if (!dp_res.get())
189187
return false;
190188

engine/cli/commands/model_pull_cmd.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ std::optional<std::string> ModelPullCmd::Exec(const std::string& host, int port,
9696

9797
CTL_INF("model: " << model << ", model_id: " << model_id);
9898

99-
// Send request download model to server
100-
CLI_LOG("Validating download items, please wait..")
10199
Json::Value json_data;
102100
json_data["model"] = model;
103101
auto data_str = json_data.toStyledString();

engine/controllers/models.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ void Models::ListModel(
153153
Json::Value ret;
154154
ret["object"] = "list";
155155
Json::Value data(Json::arrayValue);
156-
156+
model_service_->ForceIndexingModelList();
157157
// Iterate through directory
158158

159159
cortex::db::Models modellist_handler;

engine/database/models.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,11 @@ cpp::result<bool, std::string> Models::UpdateModelAlias(
262262
cpp::result<bool, std::string> Models::DeleteModelEntry(
263263
const std::string& identifier) {
264264
try {
265+
// delete only if its there
266+
if (!HasModel(identifier)) {
267+
return true;
268+
}
269+
265270
SQLite::Statement del(
266271
db_, "DELETE from models WHERE model_id = ? OR model_alias = ?");
267272
del.bind(1, identifier);

engine/main.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "controllers/server.h"
1111
#include "cortex-common/cortexpythoni.h"
1212
#include "services/config_service.h"
13+
#include "services/file_watcher_service.h"
1314
#include "services/model_service.h"
1415
#include "utils/archive_utils.h"
1516
#include "utils/cortex_utils.h"
@@ -107,6 +108,7 @@ void RunServer(std::optional<int> port, bool ignore_cout) {
107108
auto event_queue_ptr = std::make_shared<EventQueue>();
108109
cortex::event::EventProcessor event_processor(event_queue_ptr);
109110

111+
auto model_dir_path = file_manager_utils::GetModelsContainerPath();
110112
auto config_service = std::make_shared<ConfigService>();
111113
auto download_service =
112114
std::make_shared<DownloadService>(event_queue_ptr, config_service);
@@ -116,6 +118,10 @@ void RunServer(std::optional<int> port, bool ignore_cout) {
116118
auto model_service = std::make_shared<ModelService>(
117119
download_service, inference_svc, engine_service);
118120

121+
auto file_watcher_srv = std::make_shared<FileWatcherService>(
122+
model_dir_path.string(), model_service);
123+
file_watcher_srv->start();
124+
119125
// initialize custom controllers
120126
auto engine_ctl = std::make_shared<Engines>(engine_service);
121127
auto model_ctl = std::make_shared<Models>(model_service, engine_service);

0 commit comments

Comments
 (0)