| 54 | } |
| 55 | |
| 56 | void ClientRunner::run_get_models_request(std::unique_ptr<http::HttpRequestCallback> answer_callback) { |
| 57 | auto proxy_target = get_ready_proxy_target(); |
| 58 | if (!proxy_target || !proxy_target->is_ready()) { |
| 59 | return http_send_static_answer(503 /* service unavailable */, "no working proxy connections", |
| 60 | std::move(answer_callback)); |
| 61 | } |
| 62 | |
| 63 | auto connection = static_cast<ClientProxyConnection *>(get_connection(proxy_target->connection_id())); |
| 64 | if (!connection || !connection->is_ready()) { |
| 65 | return http_send_static_answer(503 /* service unavailable */, "no working proxy connections", |
| 66 | std::move(answer_callback)); |
| 67 | } |
| 68 | |
| 69 | auto request = cocoon::create_serialize_tl_object<cocoon_api::client_getWorkerTypesV2>(); |
| 70 | send_query_to_connection( |
| 71 | proxy_target->connection_id(), "request", std::move(request), td::Timestamp::in(10.0), |
| 72 | [answer_callback = std::move(answer_callback)](td::Result<td::BufferSlice> R) mutable { |
| 73 | if (R.is_error()) { |
| 74 | return http_send_static_answer(R.move_as_error_prefix("got error from proxy: "), std::move(answer_callback)); |
| 75 | } |
| 76 | |
| 77 | auto b = R.move_as_ok(); |
| 78 | auto R2 = cocoon::fetch_tl_object<cocoon_api::client_workerTypesV2>(std::move(b), true); |
| 79 | if (R2.is_error()) { |
| 80 | return http_send_static_answer(R2.move_as_error_prefix("got invalid result from proxy: "), |
| 81 | std::move(answer_callback)); |
| 82 | } |
| 83 | auto obj = R2.move_as_ok(); |
| 84 | SimpleJsonSerializer jb; |
| 85 | jb.start_object(); |
| 86 | jb.add_element("object", "list"); |
| 87 | jb.start_array("data"); |
| 88 | for (size_t i = 0; i < obj->types_.size(); i++) { |
| 89 | auto &e = obj->types_[i]; |
| 90 | jb.start_object(); |
| 91 | jb.add_element("id", e->name_); |
| 92 | jb.add_element("object", "model"); |
| 93 | jb.add_element("created", 0); |
| 94 | jb.add_element("owned_by", "?"); |
| 95 | jb.start_array("workers"); |
| 96 | for (auto &w : e->workers_) { |
| 97 | jb.start_object(); |
| 98 | jb.add_element("coefficient", w->coefficient_); |
| 99 | jb.add_element("running_requests", w->active_requests_); |
| 100 | jb.add_element("max_running_requests", w->max_active_requests_); |
| 101 | jb.stop_object(); |
| 102 | } |
| 103 | jb.stop_array(); |
| 104 | jb.stop_object(); |
| 105 | } |
| 106 | jb.stop_array(); |
| 107 | jb.add_element("object", "list"); |
| 108 | jb.stop_object(); |
| 109 | |
| 110 | auto res = jb.as_cslice().str(); |
| 111 | http_send_static_answer(std::move(res), std::move(answer_callback), "application/json"); |
| 112 | }); |
| 113 | } |
nothing calls this directly
no test coverage detected