| 770 | } |
| 771 | |
| 772 | bool server_models::ensure_model_ready(const std::string & name) { |
| 773 | auto meta = get_meta(name); |
| 774 | if (!meta.has_value()) { |
| 775 | throw std::runtime_error("model name=" + name + " is not found"); |
| 776 | } |
| 777 | if (meta->is_ready()) { |
| 778 | return false; // ready for taking requests |
| 779 | } |
| 780 | if (meta->status == SERVER_MODEL_STATUS_SLEEPING) { |
| 781 | return false; // child is sleeping but still running; new request will wake it up |
| 782 | } |
| 783 | if (meta->status == SERVER_MODEL_STATUS_UNLOADED) { |
| 784 | SRV_INF("model name=%s is not loaded, loading...\n", name.c_str()); |
| 785 | load(name); |
| 786 | } |
| 787 | |
| 788 | // wait for loading to complete |
| 789 | SRV_INF("waiting until model name=%s is fully loaded...\n", name.c_str()); |
| 790 | wait_until_loading_finished(name); |
| 791 | |
| 792 | // check final status |
| 793 | meta = get_meta(name); |
| 794 | if (!meta.has_value() || meta->is_failed()) { |
| 795 | throw std::runtime_error("model name=" + name + " failed to load"); |
| 796 | } |
| 797 | |
| 798 | return true; |
| 799 | } |
| 800 | |
| 801 | server_http_res_ptr server_models::proxy_request(const server_http_req & req, const std::string & method, const std::string & name, bool update_last_used) { |
| 802 | auto meta = get_meta(name); |
no test coverage detected