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