From f7f17e6dcc7a7fbd40a5c1aa38c6aa9c1901096e Mon Sep 17 00:00:00 2001 From: lstocchi Date: Tue, 30 Jan 2024 15:15:49 +0100 Subject: [PATCH] fix: wait for the model service to be started before checking the sample app Signed-off-by: lstocchi --- .../src/managers/applicationManager.ts | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/packages/backend/src/managers/applicationManager.ts b/packages/backend/src/managers/applicationManager.ts index ecf4a0832..331d8b727 100644 --- a/packages/backend/src/managers/applicationManager.ts +++ b/packages/backend/src/managers/applicationManager.ts @@ -127,31 +127,28 @@ export class ApplicationManager { // most probably the sample app will fail at starting as it tries to connect to the model_service which is still loading the model // so we check if the endpoint is ready before to restart the sample app - // wait 5 secs to give the time to the sample app to connect to the model service - await timeout(5000); // check if sample app container actually started const sampleApp = podInfo.containers?.find(container => !container.modelService); if (sampleApp) { - const sampleAppContainerInspectInfo = await containerEngine.inspectContainer(podInfo.engineId, sampleApp.name); - if (!sampleAppContainerInspectInfo.State.Running) { - const modelServiceContainer = podInfo.containers?.find(container => container.modelService); - if (modelServiceContainer) { - const modelServicePortMapping = podInfo.portmappings.find( - port => port.container_port === Number(modelServiceContainer.ports[0]), - ); - if (modelServicePortMapping) { - await this.restartContainerWhenModelServiceIsUp( - podInfo.engineId, - `http://localhost:${modelServicePortMapping.host_port}`, - sampleApp, - ).catch((e: unknown) => { - console.error(String(e)); - }); - } + const modelServiceContainer = podInfo.containers?.find(container => container.modelService); + if (modelServiceContainer) { + const modelServicePortMapping = podInfo.portmappings.find( + port => port.container_port === Number(modelServiceContainer.ports[0]), + ); + if (modelServicePortMapping) { + await this.restartContainerWhenModelServiceIsUp( + podInfo.engineId, + `http://localhost:${modelServicePortMapping.host_port}`, + sampleApp, + ).catch((e: unknown) => { + console.error(String(e)); + }); } } } + + taskUtil.setTask({ id: `running-${podInfo.Id}`, state: 'success', @@ -166,7 +163,10 @@ export class ApplicationManager { ): Promise { const alive = await isEndpointAlive(modelServiceEndpoint); if (alive) { - await containerEngine.startContainer(engineId, container.name); + const sampleAppContainerInspectInfo = await containerEngine.inspectContainer(engineId, container.name); + if (!sampleAppContainerInspectInfo.State.Running) { + await containerEngine.startContainer(engineId, container.name); + } return; } await timeout(5000);