Skip to content

Commit

Permalink
Merge pull request #1705 from janhq/j/add-file-watcher
Browse files Browse the repository at this point in the history
feat: add file watcher service
  • Loading branch information
namchuai authored Nov 21, 2024
2 parents f5c3b02 + e77d439 commit afe556d
Show file tree
Hide file tree
Showing 8 changed files with 396 additions and 6 deletions.
2 changes: 0 additions & 2 deletions engine/cli/commands/engine_install_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,6 @@ bool EngineInstallCmd::Exec(const std::string& engine,
return false;
}

CLI_LOG("Validating download items, please wait..")

if (!dp_res.get())
return false;

Expand Down
2 changes: 0 additions & 2 deletions engine/cli/commands/model_pull_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ std::optional<std::string> ModelPullCmd::Exec(const std::string& host, int port,

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

// Send request download model to server
CLI_LOG("Validating download items, please wait..")
Json::Value json_data;
json_data["model"] = model;
auto data_str = json_data.toStyledString();
Expand Down
2 changes: 1 addition & 1 deletion engine/controllers/models.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ void Models::ListModel(
Json::Value ret;
ret["object"] = "list";
Json::Value data(Json::arrayValue);

model_service_->ForceIndexingModelList();
// Iterate through directory

cortex::db::Models modellist_handler;
Expand Down
5 changes: 5 additions & 0 deletions engine/database/models.cc
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@ cpp::result<bool, std::string> Models::UpdateModelAlias(
cpp::result<bool, std::string> Models::DeleteModelEntry(
const std::string& identifier) {
try {
// delete only if its there
if (!HasModel(identifier)) {
return true;
}

SQLite::Statement del(
db_, "DELETE from models WHERE model_id = ? OR model_alias = ?");
del.bind(1, identifier);
Expand Down
6 changes: 6 additions & 0 deletions engine/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "controllers/server.h"
#include "cortex-common/cortexpythoni.h"
#include "services/config_service.h"
#include "services/file_watcher_service.h"
#include "services/model_service.h"
#include "utils/archive_utils.h"
#include "utils/cortex_utils.h"
Expand Down Expand Up @@ -107,6 +108,7 @@ void RunServer(std::optional<int> port, bool ignore_cout) {
auto event_queue_ptr = std::make_shared<EventQueue>();
cortex::event::EventProcessor event_processor(event_queue_ptr);

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

auto file_watcher_srv = std::make_shared<FileWatcherService>(
model_dir_path.string(), model_service);
file_watcher_srv->start();

// initialize custom controllers
auto engine_ctl = std::make_shared<Engines>(engine_service);
auto model_ctl = std::make_shared<Models>(model_service, engine_service);
Expand Down
Loading

0 comments on commit afe556d

Please sign in to comment.