diff --git a/backend/moment/moment-server/core/src/main/java/com/moment/core/service/TripService.java b/backend/moment/moment-server/core/src/main/java/com/moment/core/service/TripService.java index 9695f09645..0e62eceb40 100644 --- a/backend/moment/moment-server/core/src/main/java/com/moment/core/service/TripService.java +++ b/backend/moment/moment-server/core/src/main/java/com/moment/core/service/TripService.java @@ -73,9 +73,9 @@ public Trip delete(Long tripId) { public void update(Long userId, TripRequestDTO.UpdateTrip trip) { Trip oldTrip = this.delete(trip.getTripId()); this.register(TripRequestDTO.RegisterTrip.builder() - .startDate(oldTrip.getStartDate()) - .endDate(oldTrip.getEndDate()) - .tripName(oldTrip.getTripName()) + .startDate(trip.getStartDate()) + .endDate(trip.getEndDate()) + .tripName(trip.getTripName()) .build(), userId); } diff --git a/backend/moment/moment-server/core/src/main/java/com/moment/core/service/UserService.java b/backend/moment/moment-server/core/src/main/java/com/moment/core/service/UserService.java index 00208d0a6b..ae80dc3344 100644 --- a/backend/moment/moment-server/core/src/main/java/com/moment/core/service/UserService.java +++ b/backend/moment/moment-server/core/src/main/java/com/moment/core/service/UserService.java @@ -95,7 +95,7 @@ public void updateUserSetting(UserRequestDTO.updateUser request, Long userId) { public void deleteUser(Long userId) { User user = userRepository.findById(userId).orElseThrow(() -> new IllegalArgumentException("존재하지 않는 유저입니다.")); // S3 먼저 전부 삭제 -// s3Service.deleteFile("", String.valueOf(userId)); + s3Service.deleteFile("", String.valueOf(userId)); // 유저의 영수증 전부 삭제 receiptRepository.deleteAllByUser(user); // 유저의 imageFile 전부 삭제 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 26f6040277..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 @@ -1,6 +1,8 @@ package com.moment.scheduler.config; +import com.moment.scheduler.domain.cardView.CardViewRepository; import com.moment.scheduler.domain.user.UserRepository; +import com.moment.scheduler.service.CardViewService; import com.moment.scheduler.service.NotiService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -16,10 +18,12 @@ public class SchedulerConfiguration { private final NotiService notiService; private final UserRepository userRepository; + private final CardViewService cardViewService; + private final CardViewRepository cardViewRepository; // 매일 오후 1시에 알림 발송 -// @Scheduled(cron = "0 0 13 * * *") - @Scheduled(cron = "22 06 * * * *") + @Scheduled(cron = "0 0 14 * * *") +// @Scheduled(cron = "22 06 * * * *") public void run() { log.info("Noti Scheduler is running"); try { @@ -30,4 +34,19 @@ public void run() { 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..c6f4ec8eb8 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 @@ -41,7 +41,7 @@ public SchedulerResponseDTO.AIModelRunResponseDTO getIncompleteCardViews() throw if (awsService.isEc2Running()){ throw new RuntimeException("EC2 is already running"); } - awsService.turnOnOrOff("moment-ai-t4", true); + awsService.turnOnOrOff("moment", 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,7 +115,7 @@ 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", false); // 분석한만큼 유저에게 알림을 전송 for (User user : userCardViewCount.keySet()){ 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 a673e3d770..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 @@ -71,19 +71,35 @@ public void sendQuestionNoti(User user, String question) { } if (!isTraveling){ log.info("User {} is not traveling today", user.getId()); - return; - } - 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()); + int rand = (int) (Math.random() * 10); + if (rand % 2 == 0){ + log.info("Sending random notification to user {}", user.getId()); + try { + ResponseEntity ret = notiClient.pushMessage( + FcmSendDto.builder() + .token(user.getFirebaseToken()) + .title("moment") + .body("문득 갑자기 떠나보는건 어때요?") + .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()); + } } }