def wait_for_model(rest_port, model_name, timeout_seconds, wait_interval_seconds=5): tfs_url = "http://localhost:{}/v1/models/{}".format(rest_port, model_name) with timeout(timeout_seconds): while True: try: session = requests.Session() retries = Retry(total=9, backoff_factor=0.1) session.mount( "http://", requests.adapters.HTTPAdapter(max_retries=retries)) log.info( "Trying to connect with model server: {}".format(tfs_url)) response = session.get(tfs_url) log.info(response) if response.status_code == 200: versions = json.loads( response.content)["model_version_status"] if all(version["state"] == "AVAILABLE" for version in versions): break except ( ConnectionRefusedError, NewConnectionError, MaxRetryError, requests.exceptions.ConnectionError, ): log.warning("model: {} is not available yet ".format(tfs_url)) time.sleep(wait_interval_seconds) log.info("model: {} is available now".format(tfs_url))
def _wait_for_model(self, model_name): url = "http://localhost:{}/v1/models/{}".format(self._model_tfs_rest_port[model_name], model_name) with timeout(): while True: time.sleep(0.5) try: response = requests.get(url) if response.status_code == 200: versions = json.loads(response.content)['model_version_status'] if all(version["state"] == "AVAILABLE" for version in versions): break except ConnectionError: log.exception("Failed to load models.")
def _wait_for_model(self, model_name): url = "http://localhost:{}/v1/models/{}".format(self._model_tfs_rest_port[model_name], model_name) with timeout(): while True: time.sleep(0.5) try: session = requests.Session() retries = Retry(total=9, backoff_factor=0.1) session.mount('http://', requests.adapters.HTTPAdapter(max_retries=retries)) response = session.get(url) if response.status_code == 200: versions = json.loads(response.content)['model_version_status'] if all(version["state"] == "AVAILABLE" for version in versions): break except ConnectionError: log.exception("Failed to load models.")