From c239d64914ecb31cd509a70d608f044af389163c Mon Sep 17 00:00:00 2001 From: j-yong99 Date: Thu, 30 May 2024 10:37:25 +0900 Subject: [PATCH 1/2] =?UTF-8?q?:sparkles:=20=EC=A0=84=EC=8B=9C=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/SchedulerConfiguration.java | 26 +++++++++---------- .../scheduler/service/CardViewService.java | 18 ++++++------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/backend/moment/moment-server/scheduler/src/main/java/com/moment/scheduler/config/SchedulerConfiguration.java b/backend/moment/moment-server/scheduler/src/main/java/com/moment/scheduler/config/SchedulerConfiguration.java index 1315f0596c..ede9718233 100644 --- a/backend/moment/moment-server/scheduler/src/main/java/com/moment/scheduler/config/SchedulerConfiguration.java +++ b/backend/moment/moment-server/scheduler/src/main/java/com/moment/scheduler/config/SchedulerConfiguration.java @@ -36,17 +36,17 @@ public void run() { } // 매 한시간마다 분석요청 - @Scheduled(cron = "0 0 * * * *") - public void run2() { - log.info("Analysis Scheduler is running"); - try { - // 만약 분석중인 카드뷰가 하나라도 있는 경우 - if (!cardViewRepository.findAllByRecordFileStatusIn(List.of("WAIT")).isEmpty()) { - cardViewService.getIncompleteCardViews(); - } - - } catch (Exception e) { - log.error("Failed to send notification"); - } - } +// @Scheduled(cron = "0 0 * * * *") +// public void run2() { +// log.info("Analysis Scheduler is running"); +// try { +// // 만약 분석중인 카드뷰가 하나라도 있는 경우 +// if (!cardViewRepository.findAllByRecordFileStatusIn(List.of("WAIT")).isEmpty()) { +// cardViewService.getIncompleteCardViews(); +// } +// +// } catch (Exception e) { +// log.error("Failed to send notification"); +// } +// } } \ No newline at end of file diff --git a/backend/moment/moment-server/scheduler/src/main/java/com/moment/scheduler/service/CardViewService.java b/backend/moment/moment-server/scheduler/src/main/java/com/moment/scheduler/service/CardViewService.java index 8f5408987f..cdf240a736 100644 --- a/backend/moment/moment-server/scheduler/src/main/java/com/moment/scheduler/service/CardViewService.java +++ b/backend/moment/moment-server/scheduler/src/main/java/com/moment/scheduler/service/CardViewService.java @@ -38,10 +38,10 @@ public class CardViewService { public SchedulerResponseDTO.AIModelRunResponseDTO getIncompleteCardViews() throws InterruptedException { // ec2가 켜져있는지 확인 - if (awsService.isEc2Running()){ - throw new RuntimeException("EC2 is already running"); - } - awsService.turnOnOrOff("moment-ai-t4", true); +// if (awsService.isEc2Running()){ +// throw new RuntimeException("EC2 is already running"); +// } +// awsService.turnOnOrOff("moment-ai-t4", true); log.info("EC2 trying to turn on"); while (!awsService.isEc2Running()){ log.info("sleep"); @@ -50,7 +50,7 @@ public SchedulerResponseDTO.AIModelRunResponseDTO getIncompleteCardViews() throw // 분석 완료 카드뷰 개수를 유저별로 저장 Map userCardViewCount = new HashMap<>(); - sleep(31000); +// sleep(31000); // 경과 시간 체크를 위한 시작 시간 long startTime = System.currentTimeMillis(); List cards = cardViewRepository.findAllByRecordFileStatusIn(List.of("WAIT")); @@ -115,16 +115,16 @@ public SchedulerResponseDTO.AIModelRunResponseDTO getIncompleteCardViews() throw } long endTime = System.currentTimeMillis(); log.info("AI model run time : " + (endTime - startTime) + "ms"); - awsService.turnOnOrOff("moment-ai-t4", false); +// awsService.turnOnOrOff("moment-ai-t4", false); // 분석한만큼 유저에게 알림을 전송 for (User user : userCardViewCount.keySet()){ notiService.sendFinishNoti(user, userCardViewCount.get(user)); } - while (awsService.isEc2Running()){ - sleep(5000); - } +// while (awsService.isEc2Running()){ +// sleep(5000); +// } return SchedulerResponseDTO.AIModelRunResponseDTO.builder() .failRecordNum(failRecordNum) .successRecordNum(successRecordNum) From 4f05f7ef8b75888225c80a6eed958dee8540f574 Mon Sep 17 00:00:00 2001 From: j-yong99 Date: Thu, 30 May 2024 10:38:06 +0900 Subject: [PATCH 2/2] =?UTF-8?q?:sparkles:=20=EC=A0=84=EC=8B=9C=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../moment/scheduler/service/NotiService.java | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/backend/moment/moment-server/scheduler/src/main/java/com/moment/scheduler/service/NotiService.java b/backend/moment/moment-server/scheduler/src/main/java/com/moment/scheduler/service/NotiService.java index 6c15eb5de6..871fc23fe9 100644 --- a/backend/moment/moment-server/scheduler/src/main/java/com/moment/scheduler/service/NotiService.java +++ b/backend/moment/moment-server/scheduler/src/main/java/com/moment/scheduler/service/NotiService.java @@ -87,18 +87,19 @@ public void sendQuestionNoti(User user, String question) { log.error("Failed to send notification to user {}", user.getId()); } } - } - try { - ResponseEntity ret = notiClient.pushMessage( - FcmSendDto.builder() - .token(user.getFirebaseToken()) - .title("moment") - .body(question) - .build() - ); - log.info("Notification sent to user {} with response {}", user.getId(), ret); - } catch (Exception e){ - log.error("Failed to send notification to user {}", user.getId()); + }else{ + try { + ResponseEntity ret = notiClient.pushMessage( + FcmSendDto.builder() + .token(user.getFirebaseToken()) + .title("moment") + .body(question) + .build() + ); + log.info("Notification sent to user {} with response {}", user.getId(), ret); + } catch (Exception e){ + log.error("Failed to send notification to user {}", user.getId()); + } } }