Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wait for the model service to be started before checking the sam… #196

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/backend/src/managers/applicationManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,11 @@ describe('restartContainerWhenModelServiceIsUp', () => {
{} as unknown as ModelsManager,
);
test('restart container if endpoint is alive', async () => {
mocks.inspectContainerMock.mockResolvedValue({
State: {
Running: false,
},
});
vi.spyOn(utils, 'isEndpointAlive').mockResolvedValue(true);
await manager.restartContainerWhenModelServiceIsUp('engine', 'endpoint', containerAttachedInfo);
expect(mocks.startContainerMock).toBeCalledWith('engine', 'name');
Expand Down Expand Up @@ -802,11 +807,6 @@ describe('runApplication', () => {
Promise.resolve(),
);
vi.spyOn(utils, 'timeout').mockResolvedValue();
mocks.inspectContainerMock.mockResolvedValue({
State: {
Running: false,
},
});
await manager.runApplication(pod, taskUtils);
expect(mocks.startPod).toBeCalledWith(pod.engineId, pod.Id);
expect(restartContainerWhenEndpointIsUpMock).toBeCalledWith(pod.engineId, 'http://localhost:9001', {
Expand Down
36 changes: 17 additions & 19 deletions packages/backend/src/managers/applicationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,27 +114,22 @@ 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));
});
}
}
}
Expand All @@ -153,7 +148,10 @@ export class ApplicationManager {
): Promise<void> {
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);
Expand Down
Loading