스케줄 aop 동작안함으로 구조 변경

This commit is contained in:
2025-08-05 18:21:35 +09:00
parent b0a99ca55f
commit b01c355492
11 changed files with 109 additions and 73 deletions

View File

@@ -1,6 +1,8 @@
package com.caliverse.admin.scheduler;
import com.caliverse.admin.domain.entity.log.LogAction;
import com.caliverse.admin.domain.entity.log.LogStatus;
import com.caliverse.admin.global.component.manager.BusinessProcessIdManager;
import com.caliverse.admin.mongodb.service.BusinessLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@@ -13,9 +15,11 @@ import java.util.Map;
public abstract class CommonScheduler implements Scheduler {
protected final BusinessLogService businessLogService;
protected final BusinessProcessIdManager processIdManager;
protected CommonScheduler(BusinessLogService businessLogService) {
protected CommonScheduler(BusinessLogService businessLogService, BusinessProcessIdManager processIdManager) {
this.businessLogService = businessLogService;
this.processIdManager = processIdManager;
}
@Override
@@ -46,4 +50,15 @@ public abstract class CommonScheduler implements Scheduler {
* 스케줄러 구현체에서 실제 작업을 수행하는 메소드
*/
protected abstract void executeInternal();
protected void executeWithProcessId(LogAction action, Runnable businessLogic) {
processIdManager.createNewProcessId();
processIdManager.setCurrentAction(action);
try {
businessLogic.run();
} finally {
processIdManager.clear();
}
}
}

View File

@@ -5,6 +5,7 @@ import com.caliverse.admin.domain.entity.log.LogAction;
import com.caliverse.admin.domain.entity.log.LogStatus;
import com.caliverse.admin.domain.service.BattleEventService;
import com.caliverse.admin.global.common.annotation.BusinessProcess;
import com.caliverse.admin.global.component.manager.BusinessProcessIdManager;
import com.caliverse.admin.mongodb.service.BusinessLogService;
import com.caliverse.admin.scheduler.CommonScheduler;
import com.caliverse.admin.scheduler.entity.SchedulerType;
@@ -26,14 +27,18 @@ public class BattleEventScheduler extends CommonScheduler {
private final BattleEventService battleEventService;
public BattleEventScheduler(BattleEventService battleEventService,
BusinessLogService businessLogService) {
super(businessLogService);
BusinessLogService businessLogService,
BusinessProcessIdManager processIdManager) {
super(businessLogService, processIdManager);
this.battleEventService = battleEventService;
}
@BusinessProcess(action = LogAction.SCHEDULE_BATTLE_EVENT)
@Override
protected void executeInternal() {
executeWithProcessId(LogAction.SCHEDULE_BATTLE_EVENT, this::executeLogic);
}
private void executeLogic(){
List<BattleEvent> eventList = battleEventService.getScheduleBattleEventList();
LocalDateTime startTime = LocalDateTime.now();
@@ -89,24 +94,33 @@ public class BattleEventScheduler extends CommonScheduler {
eventIds.add(event.getId());
processCount.incrementAndGet();
}
}else if(status.equals(BattleEvent.BATTLE_STATUS.RUNNING) || status.equals(BattleEvent.BATTLE_STATUS.STOP)){
}else if(status.equals(BattleEvent.BATTLE_STATUS.RUNNING)){
if(!(!now.isBefore(todayStart) && !now.isAfter(todayEnd))){
if(!baseDate.isBefore(end_dt.toLocalDate())){
change_status = BattleEvent.BATTLE_STATUS.END;
processCount.incrementAndGet();
}else{
change_status = status.equals(BattleEvent.BATTLE_STATUS.STOP) ? BattleEvent.BATTLE_STATUS.STOP : BattleEvent.BATTLE_STATUS.WAIT;
if (change_status.equals(BattleEvent.BATTLE_STATUS.STOP)) {
processCount.incrementAndGet();
} else {
processCount.incrementAndGet();
}
} else {
change_status = BattleEvent.BATTLE_STATUS.WAIT;
}
log.info("battle event_id: {}, start_dt: {}, end_dt: {}, todayStart: {}, todayEnd: {} STATUS CHANGE {}", event.getId(), start_dt, end_dt, todayStart, todayEnd, change_status);
log.info("battle event_id: {}, start_dt: {}, end_dt: {}, todayStart: {}, todayEnd: {} STATUS CHANGE {}",
event.getId(), start_dt, end_dt, todayStart, todayEnd, change_status);
map.put("status", change_status);
battleEventService.updateBattleEventStatus(map);
eventIds.add(event.getId());
processCount.incrementAndGet();
}
} else if(status.equals(BattleEvent.BATTLE_STATUS.STOP)){
if(!baseDate.isBefore(end_dt.toLocalDate())){
change_status = BattleEvent.BATTLE_STATUS.END;
log.info("battle event_id: {}, end_dt: {}, baseDate: {} STATUS CHANGE END (from STOP)",
event.getId(), end_dt, baseDate);
map.put("status", change_status);
battleEventService.updateBattleEventStatus(map);
eventIds.add(event.getId());
processCount.incrementAndGet();
}
}
});

View File

@@ -6,6 +6,7 @@ import com.caliverse.admin.domain.entity.log.LogStatus;
import com.caliverse.admin.domain.service.BlackListService;
import com.caliverse.admin.domain.service.UserGameSessionService;
import com.caliverse.admin.global.common.annotation.BusinessProcess;
import com.caliverse.admin.global.component.manager.BusinessProcessIdManager;
import com.caliverse.admin.mongodb.service.BusinessLogService;
import com.caliverse.admin.scheduler.CommonScheduler;
import com.caliverse.admin.scheduler.entity.SchedulerType;
@@ -27,15 +28,20 @@ public class BlackListScheduler extends CommonScheduler {
public BlackListScheduler(UserGameSessionService userGameSessionService,
BlackListService blackListService,
BusinessLogService businessLogService) {
super(businessLogService);
BusinessLogService businessLogService,
BusinessProcessIdManager processIdManager) {
super(businessLogService, processIdManager);
this.userGameSessionService = userGameSessionService;
this.blackListService = blackListService;
}
@BusinessProcess(action = LogAction.SCHEDULE_BLACK_LIST)
@Override
protected void executeInternal() {
executeWithProcessId(LogAction.SCHEDULE_BLACK_LIST, this::executeLogic);
}
private void executeLogic() {
List<BlackList> blackList = blackListService.getScheduleBlackList();
LocalDateTime startTime = LocalDateTime.now();

View File

@@ -14,6 +14,7 @@ import com.caliverse.admin.dynamodb.service.DynamodbLandAuctionService;
import com.caliverse.admin.dynamodb.service.DynamodbLandService;
import com.caliverse.admin.dynamodb.service.DynamodbService;
import com.caliverse.admin.global.common.annotation.BusinessProcess;
import com.caliverse.admin.global.component.manager.BusinessProcessIdManager;
import com.caliverse.admin.mongodb.service.BusinessLogService;
import com.caliverse.admin.scheduler.CommonScheduler;
import com.caliverse.admin.scheduler.entity.SchedulerType;
@@ -41,17 +42,21 @@ public class DataInitializeScheduler extends CommonScheduler {
DynamodbDataService dynamodbDataService,
LandService landService,
DynamodbLandAuctionService dynamodbLandAuctionService,
BusinessLogService businessLogService) {
super(businessLogService);
BusinessLogService businessLogService,
BusinessProcessIdManager processIdManager) {
super(businessLogService, processIdManager);
this.dataService = dataService;
this.dynamodbDataService = dynamodbDataService;
this.landService = landService;
this.dynamodbLandAuctionService = dynamodbLandAuctionService;
}
@BusinessProcess(action = LogAction.SCHEDULE_DATA_INIT)
@Override
protected void executeInternal() {
executeWithProcessId(LogAction.SCHEDULE_DATA_INIT, this::executeLogic);
}
private void executeLogic() {
List<DataInit> scheduleList = dataService.getScheduleDataInitList();
scheduleList.forEach(dataInit -> {
@@ -66,7 +71,6 @@ public class DataInitializeScheduler extends CommonScheduler {
});
}
@BusinessProcess(action = LogAction.DATA_INIT)
private void initLandAuction(LocalDateTime createDt){
List<LandAuction> landAuctions = landService.getAllLandAuctionList();
landAuctions.forEach(landAuction -> {
@@ -77,12 +81,10 @@ public class DataInitializeScheduler extends CommonScheduler {
dynamodbDataService.InitDataLandAuction();
}
@BusinessProcess(action = LogAction.DATA_INIT)
private void initLandDesc(){
dynamodbDataService.InitDataLandDesc();
}
@BusinessProcess(action = LogAction.DATA_INIT)
private void initLandOwner(LocalDateTime createDt){
List<LandOwnerChange> landOwnerChanges = landService.getAllLandOwnerChangesList();
landOwnerChanges.forEach(dataService::initLandOwned);

View File

@@ -5,6 +5,7 @@ import com.caliverse.admin.domain.entity.log.LogAction;
import com.caliverse.admin.domain.entity.log.LogStatus;
import com.caliverse.admin.domain.service.EventService;
import com.caliverse.admin.global.common.annotation.BusinessProcess;
import com.caliverse.admin.global.component.manager.BusinessProcessIdManager;
import com.caliverse.admin.mongodb.service.BusinessLogService;
import com.caliverse.admin.scheduler.CommonScheduler;
import com.caliverse.admin.scheduler.entity.SchedulerType;
@@ -24,14 +25,18 @@ public class EventScheduler extends CommonScheduler {
private final EventService eventService;
public EventScheduler(EventService eventService,
BusinessLogService businessLogService) {
super(businessLogService);
BusinessLogService businessLogService,
BusinessProcessIdManager processIdManager) {
super(businessLogService, processIdManager);
this.eventService = eventService;
}
@BusinessProcess(action = LogAction.SCHEDULE_EVENT)
@Override
protected void executeInternal() {
executeWithProcessId(LogAction.SCHEDULE_EVENT, this::executeLogic);
}
private void executeLogic() {
List<Event> eventList = eventService.getScheduleMailList();
LocalDateTime startTime = LocalDateTime.now();

View File

@@ -10,6 +10,7 @@ import com.caliverse.admin.dynamodb.entity.ELandAuctionResult;
import com.caliverse.admin.dynamodb.entity.ELandAuctionState;
import com.caliverse.admin.global.common.annotation.BusinessProcess;
import com.caliverse.admin.global.common.utils.CommonUtils;
import com.caliverse.admin.global.component.manager.BusinessProcessIdManager;
import com.caliverse.admin.mongodb.service.BusinessLogService;
import com.caliverse.admin.scheduler.CommonScheduler;
import com.caliverse.admin.scheduler.entity.SchedulerType;
@@ -29,14 +30,18 @@ public class LandAuctionScheduler extends CommonScheduler {
private final LandService landService;
public LandAuctionScheduler(LandService landService,
BusinessLogService businessLogService) {
super(businessLogService);
BusinessLogService businessLogService,
BusinessProcessIdManager processIdManager) {
super(businessLogService, processIdManager);
this.landService = landService;
}
@BusinessProcess(action = LogAction.SCHEDULE_LAND_AUCTION)
@Override
protected void executeInternal() {
executeWithProcessId(LogAction.SCHEDULE_LAND_AUCTION, this::executeLogic);
}
private void executeLogic() {
List<LandAuction> auctionList = landService.getScheduleLandAuctionList();
LocalDateTime startTime = LocalDateTime.now();

View File

@@ -6,6 +6,7 @@ import com.caliverse.admin.domain.service.UserGameSessionService;
import com.caliverse.admin.dynamodb.service.DynamodbMailService;
import com.caliverse.admin.dynamodb.service.DynamodbService;
import com.caliverse.admin.global.common.annotation.BusinessProcess;
import com.caliverse.admin.global.component.manager.BusinessProcessIdManager;
import com.caliverse.admin.mongodb.service.BusinessLogService;
import com.caliverse.admin.scheduler.CommonScheduler;
import com.caliverse.admin.scheduler.entity.SchedulerType;
@@ -35,17 +36,22 @@ public class LandOwnerChangesScheduler extends CommonScheduler {
DynamodbLandService dynamodbLandService,
DynamodbMailService dynamodbMailService,
UserGameSessionService userGameSessionService,
BusinessLogService businessLogService) {
super(businessLogService);
BusinessLogService businessLogService,
BusinessProcessIdManager processIdManager) {
super(businessLogService, processIdManager);
this.landService = landService;
this.dynamodbLandService = dynamodbLandService;
this.dynamodbMailService = dynamodbMailService;
this.userGameSessionService = userGameSessionService;
}
@BusinessProcess(action = LogAction.SCHEDULE_LAND_OWNER_CHANGE)
@Override
protected void executeInternal() {
executeWithProcessId(LogAction.SCHEDULE_LAND_OWNER_CHANGE, this::executeLogic);
}
private void executeLogic() {
List<LandOwnerChange> scheduleList = landService.getScheduleLandOwnerChangesList();
LocalDateTime startTime = LocalDateTime.now();

View File

@@ -12,6 +12,7 @@ import com.caliverse.admin.domain.service.MailService;
import com.caliverse.admin.global.common.annotation.BusinessProcess;
import com.caliverse.admin.global.common.utils.CommonUtils;
import com.caliverse.admin.global.common.utils.ExcelUtils;
import com.caliverse.admin.global.component.manager.BusinessProcessIdManager;
import com.caliverse.admin.mongodb.service.BusinessLogService;
import com.caliverse.admin.redis.service.RedisUserInfoService;
import com.caliverse.admin.scheduler.CommonScheduler;
@@ -48,8 +49,9 @@ public class MailScheduler extends CommonScheduler {
MessageHandlerService messageHandlerService,
ScheduleService schedulerService,
ExcelUtils excelUtils,
BusinessLogService businessLogService) {
super(businessLogService);
BusinessLogService businessLogService,
BusinessProcessIdManager processIdManager) {
super(businessLogService, processIdManager);
this.mailService = mailService;
this.redisUserInfoService = redisUserInfoService;
this.messageHandlerService = messageHandlerService;
@@ -57,9 +59,12 @@ public class MailScheduler extends CommonScheduler {
this.excelUtils = excelUtils;
}
@BusinessProcess(action = LogAction.SCHEDULE_MAIL)
@Override
protected void executeInternal() {
executeWithProcessId(LogAction.SCHEDULE_MAIL, this::executeLogic);
}
private void executeLogic(){
List<Mail> mailList = mailService.getScheduleMailList();
if (mailList.isEmpty()) {

View File

@@ -9,6 +9,7 @@ import com.caliverse.admin.domain.entity.log.LogStatus;
import com.caliverse.admin.domain.service.NoticeService;
import com.caliverse.admin.global.common.annotation.BusinessProcess;
import com.caliverse.admin.global.common.utils.CommonUtils;
import com.caliverse.admin.global.component.manager.BusinessProcessIdManager;
import com.caliverse.admin.mongodb.service.BusinessLogService;
import com.caliverse.admin.redis.service.RedisUserInfoService;
import com.caliverse.admin.scheduler.CommonScheduler;
@@ -40,17 +41,21 @@ public class NoticeScheduler extends CommonScheduler {
RedisUserInfoService redisUserInfoService,
ScheduleService schedulerService,
MessageHandlerService messageHandlerService,
BusinessLogService businessLogService) {
super(businessLogService);
BusinessLogService businessLogService,
BusinessProcessIdManager processIdManager) {
super(businessLogService, processIdManager);
this.noticeService = noticeService;
this.redisUserInfoService = redisUserInfoService;
this.schedulerService = schedulerService;
this.messageHandlerService = messageHandlerService;
}
@BusinessProcess(action = LogAction.SCHEDULE_NOTICE)
@Override
protected void executeInternal() {
executeWithProcessId(LogAction.SCHEDULE_NOTICE, this::executeLogic);
}
private void executeLogic(){
List<InGame> noticeList = noticeService.getScheduleNoticeList();
if(noticeList.isEmpty()) return;

View File

@@ -1,7 +1,7 @@
package com.caliverse.admin.scheduler.polling.service;
import com.caliverse.admin.domain.entity.log.LogAction;
import com.caliverse.admin.global.common.annotation.BusinessProcess;
import com.caliverse.admin.global.component.manager.BusinessProcessIdManager;
import com.caliverse.admin.mongodb.service.BusinessLogService;
import com.caliverse.admin.scheduler.CommonScheduler;
import com.caliverse.admin.scheduler.ScheduleService;
@@ -16,14 +16,18 @@ public class cleanupScheduler extends CommonScheduler {
private final ScheduleService scheduleService;
public cleanupScheduler(ScheduleService scheduleService,
BusinessLogService businessLogService) {
super(businessLogService);
BusinessLogService businessLogService,
BusinessProcessIdManager processIdManager) {
super(businessLogService, processIdManager);
this.scheduleService = scheduleService;
}
@BusinessProcess(action = LogAction.SCHEDULE_CLEANUP)
@Override
protected void executeInternal() {
executeWithProcessId(LogAction.SCHEDULE_CLEANUP, this::executeLogic);
}
private void executeLogic() {
scheduleService.cleanupCompletedTasks();
scheduleService.cleanupMailTasks();
scheduleService.cleanupNoticeTasks();

View File

@@ -211,37 +211,6 @@
</if>
</select>
<select id="getCheckBattleEventList_bak" parameterType="com.caliverse.admin.domain.request.BattleEventRequest" resultMap="BattleEventResultMap">
SELECT id
, event_id
, repeat_type
, event_operation_time
, event_start_dt
, event_end_dt
FROM battle_event
WHERE status NOT IN ('END', 'FAIL', 'CANCEL', 'STOP')
<if test="id != null and id != ''">
AND id &lt;&gt; #{id}
</if>
AND (
/* NONE 타입인 경우 */
(repeat_type = 'NONE' AND DATE (event_start_dt) BETWEEN
DATE (#{eventStartDt})
AND DATE (#{eventEndDt}))
OR
/* DAY 타입인 경우 - 기간이 조금이라도 겹치면 가져옴 */
(repeat_type = 'DAY'
AND DATE (event_start_dt) &lt;= DATE (#{eventEndDt})
AND DATE (event_end_dt) &gt;= DATE (#{eventStartDt}))
OR
/* 요일 타입인 경우 - 기간이 겹치고 같은 요일이 있는 경우만 */
(repeat_type = #{repeatType}
AND DATE (event_start_dt) &lt;= DATE (#{eventEndDt})
AND DATE (event_end_dt) &gt;= DATE (#{eventStartDt})
)
)
</select>
<select id="chkTimeOver" parameterType="com.caliverse.admin.domain.request.BattleEventRequest" resultType="integer">
SELECT COUNT(*)
FROM battle_event