From 373639a61e7253ec1f2108a5f844b6cb672a1975 Mon Sep 17 00:00:00 2001 From: flydog98 Date: Wed, 6 Dec 2023 11:46:08 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=84=9C=EB=B2=84=20=EB=AA=A8=EB=93=9C?= =?UTF-8?q?=20=EB=B3=84=20=EC=BB=A8=ED=85=8C=EC=9D=B4=EB=84=88=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95=20=EB=B0=8F?= =?UTF-8?q?=20getContainer=20=EC=8B=9C=20=EC=BB=A8=ED=85=8C=EC=9D=B4?= =?UTF-8?q?=EB=84=88=20=EA=B2=80=EC=82=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [#246] --- .../src/containers/containers.service.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/backend/src/containers/containers.service.ts b/packages/backend/src/containers/containers.service.ts index 44a8d79..e9c8fd2 100644 --- a/packages/backend/src/containers/containers.service.ts +++ b/packages/backend/src/containers/containers.service.ts @@ -20,7 +20,9 @@ export class ContainersService { @Inject('winston') private readonly logger: Logger, private commandService: CommandService, ) { - this.initializeContainers(); + if (this.configService.get('SERVER_MODE') !== 'dev') { + this.initializeContainers(); + } } async initializeContainers() { @@ -131,10 +133,15 @@ export class ContainersService { async getContainer( quizIdParam: number | string, - maxRetries = MAX_RETRY, + retry = MAX_RETRY, ): Promise { const quizId = typeof quizIdParam === 'string' ? parseInt(quizIdParam, 10) : quizIdParam; + + if (this.configService.get('SERVER_MODE') === 'dev') { + return this.createContainer(quizId); + } + if (this.availableContainers.get(quizId).length > 0) { const containerId = this.availableContainers.get(quizId).shift(); @@ -146,10 +153,14 @@ export class ContainersService { this.availableContainers.get(quizId).push(containerId); }); + if (!(await this.isValidateContainerId(containerId))) { + return await this.createContainer(quizId); + } + return containerId; } - if (maxRetries <= 0) { + if (retry <= 0) { throw new Error('No available containers after maximum retries'); } @@ -157,7 +168,7 @@ export class ContainersService { return new Promise((resolve, reject) => { setTimeout(async () => { try { - const containerId = await this.getContainer(quizId, maxRetries - 1); + const containerId = await this.getContainer(quizId, retry - 1); resolve(containerId); } catch (error) { reject(error);