From f0c1716e583e72af9bc97b5898c3a738c68b85d0 Mon Sep 17 00:00:00 2001 From: j-yong99 Date: Mon, 17 Jun 2024 18:27:14 +0900 Subject: [PATCH] =?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 | 28 +++++++++---------- .../scheduler/service/CardViewService.java | 16 +++++------ 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 ede9718233..a663f448a2 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 @@ -35,18 +35,18 @@ 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 cdf240a736..06abb03b7e 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"); @@ -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)