Skip to content

Commit c5f8cdf

Browse files
committed
decouple server_routes and server_http
1 parent 2141a3e commit c5f8cdf

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

tools/server/server-context.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3172,9 +3172,8 @@ void server_routes::init_routes() {
31723172

31733173
this->get_models = [this](const server_http_req &) {
31743174
auto res = std::make_unique<server_res_generator>(ctx_server);
3175-
bool is_model_ready = ctx_http.is_ready.load();
31763175
json model_meta = nullptr;
3177-
if (is_model_ready) {
3176+
if (is_ready()) {
31783177
model_meta = ctx_server.model_meta();
31793178
}
31803179
bool has_mtmd = ctx_server.mctx != nullptr;

tools/server/server-context.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ struct server_context {
4141
struct server_res_generator;
4242

4343
struct server_routes {
44-
server_routes(const common_params & params, server_context & ctx_server, server_http_context & ctx_http)
45-
: params(params), ctx_server(*ctx_server.impl), ctx_http(ctx_http) {
44+
server_routes(const common_params & params, server_context & ctx_server, std::function<bool()> is_ready = []() { return true; })
45+
: params(params), ctx_server(*ctx_server.impl), is_ready(is_ready) {
4646
init_routes();
4747
}
4848

@@ -79,5 +79,5 @@ struct server_routes {
7979

8080
const common_params & params;
8181
server_context_impl & ctx_server;
82-
server_http_context & ctx_http; // for reading is_ready
82+
std::function<bool()> is_ready;
8383
};

tools/server/server.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ int main(int argc, char ** argv) {
9999
//
100100

101101
// register API routes
102-
server_routes routes(params, ctx_server, ctx_http);
102+
server_routes routes(params, ctx_server, [&ctx_http]() { return ctx_http.is_ready.load(); });
103103

104104
ctx_http.get ("/health", ex_wrapper(routes.get_health)); // public endpoint (no API key check)
105105
ctx_http.get ("/v1/health", ex_wrapper(routes.get_health)); // public endpoint (no API key check)

0 commit comments

Comments
 (0)