forked from janhq/cortex.cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver_start_cmd.h
More file actions
51 lines (42 loc) · 1.54 KB
/
server_start_cmd.h
File metadata and controls
51 lines (42 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#pragma once
#include <optional>
#include <string>
#include "utils/config_yaml_utils.h"
#include "utils/curl_utils.h"
#include "utils/logging_utils.h"
#include "utils/url_parser.h"
namespace commands {
using CortexConfig = config_yaml_utils::CortexConfig;
inline bool IsServerAlive(const std::string& host, int port) {
auto url = url_parser::Url{
/* .protocol = */ "http",
/* .host = */ host + ":" + std::to_string(port),
/* .pathParams = */ {"healthz"},
/* .queries = */ {},
};
auto res = curl_utils::SimpleGet(url.ToFullPath());
if (res.has_error()) {
CTL_WRN("Server is not alive: " << res.error());
return false;
}
return true;
}
class ServerStartCmd {
public:
bool Exec(const std::string& host, int port,
const std::optional<std::string>& log_level = std::nullopt);
bool Exec(const std::optional<std::string>& log_level,
const std::unordered_map<std::string, std::string>& options,
CortexConfig& data);
private:
void UpdateConfig(CortexConfig& data, const std::string& key,
const std::string& value);
void UpdateVectorField(
const std::string& key, const std::string& value,
std::function<void(const std::vector<std::string>&)> setter);
void UpdateNumericField(const std::string& key, const std::string& value,
std::function<void(float)> setter);
void UpdateBooleanField(const std::string& key, const std::string& value,
std::function<void(bool)> setter);
};
} // namespace commands