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

Commit 79b1486

Browse files
committed
fix: add checkedForSyncHubAt to rc
1 parent 0a9acb0 commit 79b1486

File tree

4 files changed

+31
-11
lines changed

4 files changed

+31
-11
lines changed

engine/services/model_source_service.cc

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "database/models.h"
55
#include "json/json.h"
66
#include "utils/curl_utils.h"
7+
#include "utils/file_manager_utils.h"
78
#include "utils/huggingface_utils.h"
89
#include "utils/logging_utils.h"
910
#include "utils/string_utils.h"
@@ -464,19 +465,17 @@ ModelSourceService::AddCortexsoRepoBranch(const std::string& model_source,
464465
}
465466

466467
void ModelSourceService::SyncModelSource() {
467-
// Do interval check for 10 minutes
468-
constexpr const int kIntervalCheck = 10 * 60;
469-
auto start_time = std::chrono::steady_clock::now();
470468
while (running_) {
471469
std::this_thread::sleep_for(std::chrono::milliseconds(500));
472-
auto current_time = std::chrono::steady_clock::now();
473-
auto elapsed_time = std::chrono::duration_cast<std::chrono::seconds>(
474-
current_time - start_time)
475-
.count();
476-
477-
if (elapsed_time > kIntervalCheck) {
470+
auto now = std::chrono::system_clock::now();
471+
auto config = file_manager_utils::GetCortexConfig();
472+
auto last_check =
473+
std::chrono::system_clock::time_point(
474+
std::chrono::milliseconds(config.checkedForSyncHubAt)) +
475+
std::chrono::hours(1);
476+
477+
if (now > last_check) {
478478
CTL_DBG("Start to sync cortex.db");
479-
start_time = current_time;
480479

481480
auto res = db_service_->GetModelSources();
482481
if (res.has_error()) {
@@ -519,6 +518,20 @@ void ModelSourceService::SyncModelSource() {
519518
}
520519

521520
CTL_DBG("Done sync cortex.db");
521+
522+
auto now = std::chrono::system_clock::now();
523+
auto config = file_manager_utils::GetCortexConfig();
524+
config.checkedForSyncHubAt =
525+
std::chrono::duration_cast<std::chrono::milliseconds>(
526+
now.time_since_epoch())
527+
.count();
528+
529+
auto upd_config_res =
530+
config_yaml_utils::CortexConfigMgr::GetInstance().DumpYamlConfig(
531+
config, file_manager_utils::GetConfigurationPath().string());
532+
if (upd_config_res.has_error()) {
533+
CTL_ERR("Failed to update config file: " << upd_config_res.error());
534+
}
522535
}
523536
}
524537
}

engine/utils/config_yaml_utils.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ cpp::result<void, std::string> CortexConfigMgr::DumpYamlConfig(
5050
node["sslCertPath"] = config.sslCertPath;
5151
node["sslKeyPath"] = config.sslKeyPath;
5252
node["supportedEngines"] = config.supportedEngines;
53+
node["checkedForSyncHubAt"] = config.checkedForSyncHubAt;
5354

5455
out_file << node;
5556
out_file.close();
@@ -85,7 +86,8 @@ CortexConfig CortexConfigMgr::FromYaml(const std::string& path,
8586
!node["verifyPeerSsl"] || !node["verifyHostSsl"] ||
8687
!node["verifyProxySsl"] || !node["verifyProxyHostSsl"] ||
8788
!node["supportedEngines"] || !node["sslCertPath"] ||
88-
!node["sslKeyPath"] || !node["noProxy"]);
89+
!node["sslKeyPath"] || !node["noProxy"] ||
90+
!node["checkedForSyncHubAt"]);
8991

9092
CortexConfig config = {
9193
.logFolderPath = node["logFolderPath"]
@@ -177,6 +179,9 @@ CortexConfig CortexConfigMgr::FromYaml(const std::string& path,
177179
node["supportedEngines"]
178180
? node["supportedEngines"].as<std::vector<std::string>>()
179181
: default_cfg.supportedEngines,
182+
.checkedForSyncHubAt = node["checkedForSyncHubAt"]
183+
? node["checkedForSyncHubAt"].as<uint64_t>()
184+
: default_cfg.checkedForSyncHubAt,
180185
};
181186
if (should_update_config) {
182187
l.unlock();

engine/utils/config_yaml_utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ struct CortexConfig {
6767
std::string sslCertPath;
6868
std::string sslKeyPath;
6969
std::vector<std::string> supportedEngines;
70+
uint64_t checkedForSyncHubAt;
7071
};
7172

7273
class CortexConfigMgr {

engine/utils/file_manager_utils.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ config_yaml_utils::CortexConfig GetDefaultConfig() {
189189
.sslCertPath = "",
190190
.sslKeyPath = "",
191191
.supportedEngines = config_yaml_utils::kDefaultSupportedEngines,
192+
.checkedForSyncHubAt = 0u,
192193
};
193194
}
194195

0 commit comments

Comments
 (0)