From e5103d3a035865ce3393416990dd92e008e9a39a Mon Sep 17 00:00:00 2001 From: Yechan Lee Date: Thu, 7 Dec 2023 18:13:27 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EA=B0=81=EA=B0=81=EC=9D=98=20=EC=B1=84?= =?UTF-8?q?=EC=A0=90=EC=84=9C=EB=B2=84=EA=B0=80=20=EC=9E=90=EC=8B=A0?= =?UTF-8?q?=EB=A7=8C=EC=9D=98=20=EB=8F=84=EC=BB=A4=EC=84=9C=EB=B2=84?= =?UTF-8?q?=EB=A5=BC=20=EA=B0=96=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- be/algo-with-me-score/src/main.ts | 2 +- .../src/score/services/fetch.service.ts | 12 +++++++++--- be/docker-compose.yaml | 4 ++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/be/algo-with-me-score/src/main.ts b/be/algo-with-me-score/src/main.ts index 5ef3f35..8c15a13 100644 --- a/be/algo-with-me-score/src/main.ts +++ b/be/algo-with-me-score/src/main.ts @@ -6,6 +6,6 @@ import { AppModule } from './app.module'; async function bootstrap() { const app = await NestFactory.create(AppModule); app.useLogger(app.get(WINSTON_MODULE_NEST_PROVIDER)); - await app.listen(process.env.SELF_PORT); + await app.listen(4000 + parseInt(process.env.SCORE_SERVER_ID)); } bootstrap(); diff --git a/be/algo-with-me-score/src/score/services/fetch.service.ts b/be/algo-with-me-score/src/score/services/fetch.service.ts index b7e3e09..9e0fe1a 100644 --- a/be/algo-with-me-score/src/score/services/fetch.service.ts +++ b/be/algo-with-me-score/src/score/services/fetch.service.ts @@ -1,4 +1,4 @@ -import { Inject, Injectable, InternalServerErrorException, Logger } from '@nestjs/common'; +import { Inject, Injectable, Logger } from '@nestjs/common'; import { WINSTON_MODULE_PROVIDER } from 'nest-winston'; import { ScoreResultDto } from '../dtos/score-result.dto'; @@ -38,11 +38,17 @@ export class FetchService { testcaseId: number, containerId: number, ): Promise { - const [dockerServerHost, dockerServerBasePort] = [ + const [dockerServerHost, dockerServerBasePort, scoreServerId, dockerContainerCount] = [ process.env.DOCKER_SERVER_HOST, process.env.DOCKER_SERVER_PORT, + process.env.SCORE_SERVER_ID, + process.env.DOCKER_CONTAINER_COUNT, ]; - const dockerServerPort = (parseInt(dockerServerBasePort) + containerId).toString(); + const dockerServerPort = ( + parseInt(dockerServerBasePort) + + parseInt(scoreServerId) * parseInt(dockerContainerCount) + + containerId + ).toString(); const url = `http://${dockerServerHost}:${dockerServerPort}/${competitionId}/${userId}/${problemId}/${testcaseId}`; try { const response = await fetch(url, { method: 'POST' }); diff --git a/be/docker-compose.yaml b/be/docker-compose.yaml index 9957ffb..e714806 100644 --- a/be/docker-compose.yaml +++ b/be/docker-compose.yaml @@ -31,7 +31,7 @@ services: environment: DOCKER_CONTAINER_COUNT: ${DOCKER_CONTAINER_COUNT} TZ: "Asia/Seoul" - SELF_PORT: 4000 + SCORE_SERVER_ID: 0 user: be:be restart: always @@ -50,7 +50,7 @@ services: environment: DOCKER_CONTAINER_COUNT: ${DOCKER_CONTAINER_COUNT} TZ: "Asia/Seoul" - SELF_PORT: 4001 + SCORE_SERVER_ID: 1 user: be:be restart: always