Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ repositories {

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'io.micrometer:micrometer-registry-prometheus'
implementation 'org.springframework.boot:spring-boot-starter-cache'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-validation'
Expand Down
5 changes: 2 additions & 3 deletions docker/docker-compose.nginx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ services:
ports:
- "${NGINX_PORT:-80}:80"
volumes:
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
- ./nginx/service-env.inc:/etc/nginx/conf.d/service-env.inc:ro
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
- ./nginx/service-env.inc:/etc/nginx/conf.d/service-env.inc
networks:
- app_network
restart: unless-stopped
# resolve 옵션으로 nginx가 blue/green 없이도 시작 가능

networks:
app_network:
Expand Down
16 changes: 8 additions & 8 deletions docker/nginx/default.conf
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
upstream blue {
server 54.180.220.252:8080
# server 54.180.220.252:8080
server host.docker.internal:8080;
}

upstream green {
server 54.180.220.252:8081
# server 54.180.220.252:8081
server host.docker.internal:8081;
}

# 동적으로 변경되는 upstream 변수
# 이 파일은 cd.yml에서 동적으로 생성됨
include /etc/nginx/conf.d/service-env.inc;

server {
listen 80;
listen [::]:80;
server_name _;

include /etc/nginx/conf.d/service-env.inc;

# 로그 설정
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
Expand All @@ -27,10 +28,9 @@ server {
proxy_read_timeout 600s;
send_timeout 600s;

# 기본 upstream으로 라우팅 (service-env.inc에서 설정된 값 사용)
location / {
proxy_pass http://$service_url;
proxy_set_header Host $host;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.jolupbisang.demo.application.audio.command;

import com.jolupbisang.demo.application.audio.command.dto.WhisperRestartRes;
import com.jolupbisang.demo.infrastructure.user.UserRepository;
import com.jolupbisang.demo.infrastructure.whisper.WhisperClient;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class WhisperRestartingService {

private final UserRepository userRepository;
private final WhisperClient whisperClient;

public WhisperRestartRes restart() {

return new WhisperRestartRes(whisperClient.connectToWhisperServer());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.jolupbisang.demo.application.audio.command.dto;

public record WhisperRestartRes(
boolean connected
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public class WhisperClient extends BinaryWebSocketHandler {

private final WhisperProperties whisperProperties;

private static final int MAX_RETRY_ATTEMPTS = 1;
private static final int RETRY_DELAY_SECONDS = 1;
private static final int MAX_RETRY_ATTEMPTS = 5;
private static final int RETRY_DELAY_SECONDS = 5;

@PostConstruct
public void init() {
Expand Down Expand Up @@ -155,27 +155,29 @@ public void sendRefenceVector(long groupId, List<Long> userIds, List<Integer> co
}
}

private void connectToWhisperServer() {
public boolean connectToWhisperServer() {
WebSocketClient client = new StandardWebSocketClient();
for (int attempt = 1; attempt <= MAX_RETRY_ATTEMPTS; attempt++) {
try {
whisperSession = client.execute(this, whisperProperties.getWebsocketUrl()).get();
log.info("[WhisperClient] Connection successful on attempt {}", attempt);
return;
return true;
} catch (InterruptedException | ExecutionException e) {
log.error("[WhisperClient] Connection failed on attempt {}/{}: {}", attempt, MAX_RETRY_ATTEMPTS, e.getMessage());
log.error("[WhisperClient] Connection failed on attempt {}/{}: {}", attempt, MAX_RETRY_ATTEMPTS, e.getMessage(), e);
if (attempt < MAX_RETRY_ATTEMPTS) {
try {
TimeUnit.SECONDS.sleep(RETRY_DELAY_SECONDS);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
log.error("[WhisperClient] Thread interrupted during retry delay", ie);
return;
return false;
}
}
}
}
log.error("[WhisperClient] Failed to connect to Whisper server after {} attempts. Retries exhausted.", MAX_RETRY_ATTEMPTS);

return false;
}

private int readJsonLength(ByteBuffer payload) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.jolupbisang.demo.presentation.audio;

import com.jolupbisang.demo.application.audio.command.WhisperRestartingService;
import com.jolupbisang.demo.application.audio.command.dto.WhisperRestartRes;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
public class WhisperRestartingController {

private final WhisperRestartingService restartingService;

@PostMapping("/api/v1/whisper/restart")
public ResponseEntity<WhisperRestartRes> restartWhisperSession() {

return ResponseEntity.ok(restartingService.restart());
}
}
Loading