-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #204 from SKY-HORSE-MAN-POWER/develop
[DEPLOYMENT] 경매 페이지 SSE 에러 로그 추가 및 경매 마감 스케줄러 정상 마감 시간에 돌도록 설정
- Loading branch information
Showing
13 changed files
with
264 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 29 additions & 37 deletions
66
src/main/java/com/skyhorsemanpower/auction/config/QuartzConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,43 @@ | ||
package com.skyhorsemanpower.auction.config; | ||
|
||
import com.skyhorsemanpower.auction.kafka.dto.InitialAuctionDto; | ||
import com.skyhorsemanpower.auction.quartz.AuctionClose; | ||
import lombok.RequiredArgsConstructor; | ||
import org.quartz.*; | ||
import org.quartz.spi.JobFactory; | ||
import org.springframework.boot.autoconfigure.quartz.QuartzProperties; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.scheduling.quartz.SchedulerFactoryBean; | ||
import org.springframework.scheduling.quartz.SpringBeanJobFactory; | ||
|
||
import java.time.Instant; | ||
import java.util.Date; | ||
import javax.sql.DataSource; | ||
import java.util.Properties; | ||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
public class QuartzConfig { | ||
private final Scheduler scheduler; | ||
|
||
// 경매 시작과 경매 마감의 상태 변경 스케줄링 | ||
public void schedulerUpdateAuctionStateJob(InitialAuctionDto initialAuctionDto) throws SchedulerException { | ||
// JobDataMap 생성 및 auctionUuid 설정 | ||
JobDataMap jobDataMap = new JobDataMap(); | ||
jobDataMap.put("auctionUuid", initialAuctionDto.getAuctionUuid()); | ||
private final DataSource dataSource; | ||
private final QuartzProperties quartzProperties; | ||
private final ApplicationContext applicationContext; | ||
|
||
// Job 생성 | ||
JobDetail auctionCloseJob = JobBuilder | ||
.newJob(AuctionClose.class) | ||
.withIdentity("AuctionCloseJob_" + initialAuctionDto.getAuctionUuid(), | ||
"AuctionCloseGroup") | ||
.usingJobData(jobDataMap) | ||
.withDescription("경매 마감 Job") | ||
.build(); | ||
|
||
Date auctionEndDate = Date.from(Instant.ofEpochMilli(initialAuctionDto.getAuctionStartTime())); | ||
|
||
// Trigger 생성 | ||
Trigger auctionCloseTrigger = TriggerBuilder | ||
.newTrigger() | ||
.withIdentity("AuctionCloseTrigger_" + initialAuctionDto.getAuctionUuid(), | ||
"AuctionCloseGroup") | ||
.withDescription("경매 마감 Trigger") | ||
|
||
// test용 60초 후 시작하는 스케줄러 | ||
.startAt(DateBuilder.futureDate(60, DateBuilder.IntervalUnit.SECOND)) | ||
|
||
//Todo 실제 배포에서는 auctionEndDate을 사용해야 한다. | ||
// .startAt(auctionEndDate) | ||
.build(); | ||
@Bean | ||
public JobFactory springBeanJobFactory() { | ||
SpringBeanJobFactory jobFactory = new SpringBeanJobFactory(); | ||
jobFactory.setApplicationContext(applicationContext); | ||
return jobFactory; | ||
} | ||
|
||
// 스케줄러 생성 및 Job, Trigger 등록 | ||
scheduler.scheduleJob(auctionCloseJob, auctionCloseTrigger); | ||
@Bean | ||
public SchedulerFactoryBean schedulerFactoryBean(JobFactory jobFactory) { | ||
Properties properties = new Properties(); | ||
properties.putAll(quartzProperties.getProperties()); | ||
|
||
SchedulerFactoryBean factory = new SchedulerFactoryBean(); | ||
factory.setJobFactory(jobFactory); | ||
factory.setDataSource(dataSource); | ||
factory.setQuartzProperties(properties); | ||
factory.setOverwriteExistingJobs(true); | ||
factory.setWaitForJobsToCompleteOnShutdown(true); | ||
return factory; | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
src/main/java/com/skyhorsemanpower/auction/config/QuartzJobConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.skyhorsemanpower.auction.config; | ||
|
||
import com.skyhorsemanpower.auction.kafka.data.dto.InitialAuctionDto; | ||
import com.skyhorsemanpower.auction.quartz.AuctionClose; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.quartz.*; | ||
import org.quartz.impl.StdScheduler; | ||
import org.quartz.impl.StdSchedulerFactory; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import java.time.Instant; | ||
import java.util.Date; | ||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class QuartzJobConfig { | ||
private final Scheduler scheduler; | ||
|
||
@Bean | ||
public Scheduler scheduler() throws SchedulerException { | ||
Scheduler scheduler = new StdSchedulerFactory().getScheduler(); | ||
scheduler.start(); | ||
return scheduler; | ||
} | ||
|
||
// 경매 시작과 경매 마감의 상태 변경 스케줄링 | ||
public void schedulerUpdateAuctionStateJob(InitialAuctionDto initialAuctionDto) throws SchedulerException { | ||
// JobDataMap 생성 및 auctionUuid 설정 | ||
JobDataMap jobDataMap = new JobDataMap(); | ||
jobDataMap.put("auctionUuid", initialAuctionDto.getAuctionUuid()); | ||
|
||
// Job 생성 | ||
JobDetail auctionCloseJob = JobBuilder | ||
.newJob(AuctionClose.class) | ||
.withIdentity("AuctionCloseJob_" + initialAuctionDto.getAuctionUuid(), | ||
"AuctionCloseGroup") | ||
.usingJobData(jobDataMap) | ||
.withDescription("경매 마감 Job") | ||
.build(); | ||
|
||
|
||
//todo | ||
// 테스트를 위한경매 마감 시간을 경매 시작 시간으로부터 1분 뒤로 설정 | ||
// Date auctionEndDate = Date.from(Instant.ofEpochMilli(initialAuctionDto.getAuctionStartTime()).plusSeconds(60)); | ||
|
||
// 배포에선 아래 코드 사용해야 함 | ||
Date auctionEndDate = Date.from(Instant.ofEpochMilli(initialAuctionDto.getAuctionEndTime())); | ||
log.info("Auction Close Job Will Start At >>> {}", auctionEndDate); | ||
|
||
// Trigger 생성 | ||
Trigger auctionCloseTrigger = TriggerBuilder | ||
.newTrigger() | ||
.withIdentity("AuctionCloseTrigger_" + initialAuctionDto.getAuctionUuid(), | ||
"AuctionCloseGroup") | ||
.withDescription("경매 마감 Trigger") | ||
.startAt(auctionEndDate) | ||
.build(); | ||
|
||
// 스케줄러 생성 및 Job, Trigger 등록 | ||
scheduler.scheduleJob(auctionCloseJob, auctionCloseTrigger); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/com/skyhorsemanpower/auction/kafka/data/MessageEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.skyhorsemanpower.auction.kafka.data; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
@Getter | ||
public enum MessageEnum { | ||
AUCTION_CLOSE_MESSAGE(Constant.AUCTION_CLOSE_MESSAGE); | ||
|
||
public static class Constant { | ||
public static final String AUCTION_CLOSE_MESSAGE = "경매 낙찰되었습니다."; | ||
} | ||
|
||
private final String message; | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/skyhorsemanpower/auction/kafka/data/dto/AlarmDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.skyhorsemanpower.auction.kafka.data.dto; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.ToString; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@ToString | ||
public class AlarmDto { | ||
private List<String> receiverUuids; | ||
private String message; | ||
private String eventType; | ||
|
||
@Builder | ||
public AlarmDto(List<String> receiverUuids, String message, String eventType) { | ||
this.receiverUuids = receiverUuids; | ||
this.message = message; | ||
this.eventType = eventType; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...er/auction/kafka/dto/AuctionCloseDto.java → ...ction/kafka/data/dto/AuctionCloseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...er/auction/kafka/dto/AuctionStartDto.java → ...ction/kafka/data/dto/AuctionStartDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../auction/kafka/dto/InitialAuctionDto.java → ...ion/kafka/data/dto/InitialAuctionDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.