diff --git a/src/main/java/com/kri/notihub/server/persistence/repository/SendRepository.java b/src/main/java/com/kri/notihub/server/persistence/repository/SendRepository.java index cf821b2..8058181 100644 --- a/src/main/java/com/kri/notihub/server/persistence/repository/SendRepository.java +++ b/src/main/java/com/kri/notihub/server/persistence/repository/SendRepository.java @@ -33,14 +33,20 @@ public interface SendRepository extends JpaRepository { from TSendEntity s where s.sendStatus = :sendStatus and s.sendTy in :sendTyList - and s.sendDt between :fromDt and :toDt + and s.resultCode in :resultCodes + and s.sendDt <= :now + and exists ( + select 1 + from BizLogEntity b + where b.cmid = s.cmid + ) order by s.sendIdx asc """) - List findSendListToRefreshWithinHours( + List findSendListToRefresh( List sendTyList, short sendStatus, - LocalDateTime fromDt, - LocalDateTime toDt, + List resultCodes, + LocalDateTime now, Pageable pageable ); diff --git a/src/main/java/com/kri/notihub/server/scheduler/BizLogResultScheduler.java b/src/main/java/com/kri/notihub/server/scheduler/BizLogResultScheduler.java index 2dd217e..1c948eb 100644 --- a/src/main/java/com/kri/notihub/server/scheduler/BizLogResultScheduler.java +++ b/src/main/java/com/kri/notihub/server/scheduler/BizLogResultScheduler.java @@ -38,22 +38,22 @@ public class BizLogResultScheduler { private final BizLogRepository bizLogRepository; private final BulkSendRepository bulkSendRepository; - @Value("${kri.sms.result-sync.window-hours:1}") - private long resultSyncWindowHours; - @Value("${kri.sms.result-sync.batch-size:1000}") private int resultSyncBatchSize; - @Scheduled(fixedDelayString = "${kri.sms.result-sync.fixed-delay-ms:60000}") // 나중에 증가시킬 것 + @Scheduled(fixedDelayString = "${kri.sms.result-sync.fixed-delay-ms:60000}") @Transactional(transactionManager = "transactionManager") public void syncSmsResults() { - TimeWindow window = buildWindow(resultSyncWindowHours); - List sendTyList = List.of(SendType.SMS.getCode(), SendType.LMS_MMS.getCode(), SendType.KKO_AT.getCode()); + List resultCodes = List.of( + NotihubConst.SMS_STANDBY, + NotihubConst.LMS_MMS_STANDBY, + NotihubConst.KKO_AT_STANDBY + ); while (true) { - List batch = fetchRefreshTargets(sendTyList, window, resultSyncBatchSize); + List batch = fetchRefreshTargets(sendTyList, resultCodes, resultSyncBatchSize); if (batch.isEmpty()) { return; } @@ -63,21 +63,20 @@ public class BizLogResultScheduler { BatchResult result = applyResultsAndCollectDeltas(batch, bulkCtx); persistChanges(result, bulkCtx); + + if (result.updatedSends().isEmpty()) { + return; + } } } - private TimeWindow buildWindow(long hours) { - LocalDateTime toDt = LocalDateTime.now(); - return new TimeWindow(toDt.minusHours(hours), toDt); - } - - private List fetchRefreshTargets(List sendTyList, TimeWindow window, + private List fetchRefreshTargets(List sendTyList, List resultCodes, int size) { - return sendRepository.findSendListToRefreshWithinHours( + return sendRepository.findSendListToRefresh( sendTyList, SendStatusType.STANDBY.getCode(), - window.from(), - window.to(), + resultCodes, + LocalDateTime.now(), PageRequest.of(0, size) ); } @@ -275,9 +274,6 @@ public class BizLogResultScheduler { } } - private record TimeWindow(LocalDateTime from, LocalDateTime to) { - - } private record BulkContext(Set bulkKeys, Map bulkMap) { diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 93a4139..b01757c 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -55,7 +55,6 @@ kri: sms: result-sync: fixed-delay-ms: 10000 - window-hours: 1 batch-size: 1000 auth: