Skip to content

Commit

Permalink
fix: [BE] 옵션 값 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
HKLeeeee committed Dec 7, 2023
1 parent 4ff7544 commit 28767b0
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions backEnd/api/src/run/run.gateway.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
ConnectedSocket,
OnGatewayConnection,
OnGatewayDisconnect,
SubscribeMessage,
WebSocketGateway,
WebSocketServer,
Expand All @@ -17,7 +18,7 @@ import { RunService } from './run.service';
import { Cron, CronExpression } from '@nestjs/schedule';

@WebSocketGateway({ namespace: SOCKET_EVENT.NAME_SPACE, cors: true })
export class RunGateway implements OnGatewayConnection {
export class RunGateway implements OnGatewayConnection, OnGatewayDisconnect {
@WebSocketServer()
server: Server;

Expand Down Expand Up @@ -66,7 +67,7 @@ export class RunGateway implements OnGatewayConnection {
result.result,
result.message,
);
socket.emit(SOCKET_EVENT.DONE, response.statusCode);
socket.emit(SOCKET_EVENT.DONE, response);
});
}

Expand All @@ -78,6 +79,10 @@ export class RunGateway implements OnGatewayConnection {
});
}

handleDisconnect(@ConnectedSocket() socket: Socket) {
this.connectedSockets.delete(socket.id);
}

@SubscribeMessage(SOCKET_EVENT.REQUEST)
async requestRunCode(
@ConnectedSocket() socket: Socket,
Expand All @@ -87,17 +92,12 @@ export class RunGateway implements OnGatewayConnection {
this.jobSocketInfo.set(jobID, socket.id);
}

@SubscribeMessage(SOCKET_EVENT.DISCONNECT)
disconnect(@ConnectedSocket() socket: Socket) {
this.connectedSockets.delete(socket.id);
}

@Cron(CronExpression.EVERY_5_MINUTES)
handleNotCompleteSocket() {
const Before10S = Date.now() - 20000;
const Before20S = Date.now() - 20000;
this.connectedSockets.forEach((value, key) => {
const { socket, createTime } = value;
if (createTime < Before10S) this.connectedSockets.delete(key);
if (createTime < Before20S) this.connectedSockets.delete(key);
socket.disconnect();
});
}
Expand Down

0 comments on commit 28767b0

Please sign in to comment.