Skip to content

Commit

Permalink
fix: 각각의 채점서버가 자신만의 도커서버를 갖도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
yechan2468 committed Dec 7, 2023
1 parent 7bb4491 commit e5103d3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion be/algo-with-me-score/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
12 changes: 9 additions & 3 deletions be/algo-with-me-score/src/score/services/fetch.service.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -38,11 +38,17 @@ export class FetchService {
testcaseId: number,
containerId: number,
): Promise<ICoderunResponse> {
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' });
Expand Down
4 changes: 2 additions & 2 deletions be/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down

0 comments on commit e5103d3

Please sign in to comment.