Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

타임딜 스케줄러 추가 #48

Open
daadaadaah opened this issue Jun 5, 2023 · 0 comments
Open

타임딜 스케줄러 추가 #48

daadaadaah opened this issue Jun 5, 2023 · 0 comments

Comments

@daadaadaah
Copy link
Collaborator

daadaadaah commented Jun 5, 2023

Why

  • 타임딜 관리(오픈, 종료, 다음 날 딜 상품 셋팅 등)를 자동화 하기 위해

How

요구사항

  • 타임 딜 스케줄러는 다음과 같은 역할을 한다.
  1. 처음에 몇일치 또는 몇주치 딜 상품 미리 Redis에 저장
  2. 타임딜 오픈 : Redis에 있는 딜 상품 상태를 오픈 전 -> 오픈
  3. 타임딜 종료 : Redis에 있는 딜 상품 상태를 오픈 -> 마감

구현

방법 1. AWS CloudWatch Events + AWS Lambda

  • CloudWatch Events에 대해 공부해봐야겠지만, 가장 최선의 방법이라고 생각

방법 2. @scheduled 활용하기

  • 단점 : 다중 서버 환경에서 여러 서버에서 스케줄러가 실행되므로 데이터 처리가 중복으로 발생할 것 같음
@EnableScheduling
@Service
public class DealServiceScheduler {

    @Scheduled(cron = "0 0 10 * * ?") // 매일 오전 10시에 실행
    public void openTimeDeal() {
        // Redis에 저장된 딜 상품 상태 : 오픈 전 -> 오픈
    }

    @Scheduled(cron = "0 0 11 * * ?") // 매일 오전 11시에 실행
    public void closeTimeDeal() {
        // Redis에 저장된 딜 상품 상태 : 오픈 -> 마감

        // 다음날 오픈 될 딜 상품 MySQL -> Redis로 쓰기 : 딜 상품 상태 추가해야 됨
    }
}

방법 3. batch 서버 구축

  • 단점 : 간단한 스케줄링 작업 때문에 필요한대, 24시간 동안 돌아가는건 경제적 비용 낭비라고 생각함.

Reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant