-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 회원 팔로워 수의 데이터 정합성을 배치 처리하는 쿼리 작성 * refactor: 서비스 레이어에서 명시적 flush 대신 벌크 쿼리의 flushAutomatically 모드를 true로 설정 * feat: 1시간마다 회원의 팔로워 수 정합성을 맞추는 배치 쿼리를 실행하는 스케줄러 구현
- Loading branch information
Showing
7 changed files
with
100 additions
and
6 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
backend/src/main/java/com/woowacourse/f12/application/batch/BatchService.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,20 @@ | ||
package com.woowacourse.f12.application.batch; | ||
|
||
import com.woowacourse.f12.domain.member.MemberRepository; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Component | ||
public class BatchService { | ||
|
||
private final MemberRepository memberRepository; | ||
|
||
public BatchService(final MemberRepository memberRepository) { | ||
this.memberRepository = memberRepository; | ||
} | ||
|
||
@Transactional | ||
public void updateFollowerCount() { | ||
memberRepository.updateFollowerCountBatch(); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
backend/src/main/java/com/woowacourse/f12/application/batch/FollowerCountBatchScheduler.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,25 @@ | ||
package com.woowacourse.f12.application.batch; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
|
||
@Slf4j | ||
public class FollowerCountBatchScheduler { | ||
|
||
private static final String LOG_FORMAT = "Class : {}, Message : {}"; | ||
|
||
private final BatchService batchService; | ||
|
||
public FollowerCountBatchScheduler(final BatchService batchService) { | ||
this.batchService = batchService; | ||
} | ||
|
||
@Scheduled(cron = "0 0 0/1 1/1 * ? *") | ||
public void execute() { | ||
try { | ||
batchService.updateFollowerCount(); | ||
} catch (Exception e) { | ||
log.error(LOG_FORMAT, e.getClass().getSimpleName(), e.getMessage()); | ||
} | ||
} | ||
} |
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
23 changes: 23 additions & 0 deletions
23
backend/src/main/java/com/woowacourse/f12/config/SchedulerConfig.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,23 @@ | ||
package com.woowacourse.f12.config; | ||
|
||
import com.woowacourse.f12.application.batch.BatchService; | ||
import com.woowacourse.f12.application.batch.FollowerCountBatchScheduler; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.scheduling.annotation.EnableScheduling; | ||
|
||
@EnableScheduling | ||
@Configuration | ||
public class SchedulerConfig { | ||
|
||
private final BatchService batchService; | ||
|
||
public SchedulerConfig(final BatchService batchService) { | ||
this.batchService = batchService; | ||
} | ||
|
||
@Bean(name = "followerCountBatchScheduler") | ||
public FollowerCountBatchScheduler followerCountBatchScheduler() { | ||
return new FollowerCountBatchScheduler(batchService); | ||
} | ||
} |
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
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