Skip to content

Commit

Permalink
Refac & Fix: Refactoring Code And Fix Code (#53)
Browse files Browse the repository at this point in the history
* Fix: Remove Log Code

- 중복되는 로그 코드를 제거했습니다.

* Refac: Remove @Stepscope

- JobParameter를 사용하지 않는 상황에서 @Stepscope를 사용할 이유가 없고, 메모리 적으로 싱글톤 빈을 등록하는 것이 좋아보여 제거했습니다.

* Feat: Add Log code

- 테스트 용으로 로그 코드를 추가했습니다.

* Remove : Remove Unused Code

- 사용하지 않는 코드 삭제
  • Loading branch information
Train0303 authored Feb 16, 2024
1 parent 1d8c29a commit 94f67cd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 37 deletions.
10 changes: 5 additions & 5 deletions ppap/src/main/java/com/ppap/ppap/_core/config/BatchConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ public Step fcmDeviceChunkStep(JobRepository jobRepository, PlatformTransactionM


@Bean
@StepScope
public FlatFileItemReader<NoticeDto> reader() {
return new FlatFileItemReaderBuilder<NoticeDto>()
.name("csvReader")
Expand All @@ -127,7 +126,6 @@ public FlatFileItemReader<NoticeDto> reader() {
}

@Bean
@StepScope
public NoticeWriter writer() {
return new NoticeWriter(
userJpaRepository,
Expand All @@ -138,19 +136,21 @@ public NoticeWriter writer() {
}

@Bean
@StepScope
public JdbcCursorItemReader<Device> deviceReader() {
return new JdbcCursorItemReaderBuilder<Device>()
.name("jdbcCursorDeviceReader")
.fetchSize(CHUNK_SIZE)
.dataSource(dataSource)
.rowMapper(new DeviceRowMapper())
.rowMapper((rs, rowNum) ->
Device.builder()
.id(rs.getLong("device_id"))
.fcmToken(rs.getString("fcm_token"))
.build())
.sql("SELECT device_id, fcm_token FROM device_tb")
.build();
}

@Bean
@StepScope
public DeviceWriter deviceWriter() {
return new DeviceWriter(
deviceJpaRepository,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,7 @@ public SchedulerConfig(JobLauncher jobLauncher, @Qualifier("csvReaderJob") Job c
@Scheduled(cron = "0 0/30 9-22 * * *", zone="Asia/Seoul")
@SchedulerLog(job="Notice")
public void run() {
log.info("Notice Scheduler Start");
long start = System.currentTimeMillis();
try {
schedulerService.run();
} finally{
log.info("실행시간 : {} ms", System.currentTimeMillis() - start);
log.info("Notice Scheduler end");
}
schedulerService.run();
}

@Scheduled(cron = "0 0 23 * * *", zone = "Asia/Seoul")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.google.firebase.messaging.FirebaseMessagingException;
import com.google.firebase.messaging.Message;
import com.google.firebase.messaging.Notification;
import com.google.firebase.messaging.SendResponse;
import com.ppap.ppap._core.crawler.CrawlingData;
import com.ppap.ppap._core.utils.MDCUtils;
import com.ppap.ppap.domain.subscribe.entity.Notice;
Expand Down Expand Up @@ -65,11 +66,6 @@ public void sendNotification(Map<Notice, List<CrawlingData>> filterNoticeCrawlin
return null;
}
}),executor))
.map(future -> future.exceptionally(
new MDCUtils.MDCAwareFunction<>( ex -> {
log.error(ex.getMessage());
return null;
})))
.toList();

// 두 개로 나눈 이유는 하나의 파이프라인에서 처리할 시 동기적으로 처리하게 되는 문제가 발생한다.
Expand All @@ -78,27 +74,15 @@ public void sendNotification(Map<Notice, List<CrawlingData>> filterNoticeCrawlin
.filter(Objects::nonNull)
.toList();

responseList.stream()
.flatMap(batchResponse -> batchResponse.getResponses().stream())
.forEach(response -> {
if (!response.isSuccessful()) {
log.error(response.getException().getMessagingErrorCode().toString());
}
});
}

// public String sendNotification() {
// Notification notification = Notification.builder()
// .setTitle("테스트용 타이틀")
// .setBody("테스트용 내용")
// .build();
//
// Message message = Message.builder()
// .setNotification(notification)
// .setToken("czqDaETOQQCGd59IwTU4Nr:APA91bH0jhPPMEEneSDkHSCuqSbByWv5Ts8dUeD--Ueq1cdnLls_CRD7ut1qo6TFZNw1kagPwLMj3IrHFlH7MIWLGgq3KehFolRat1_kwAEIDecUmaTSDBA7gFAKwDNRPtlRT6uT5E1-")
// .build();
//
// ApiFuture<String> future = firebaseMessaging.sendAsync(message);
// future.addListener(() -> {
// if(future.isDone()) log.info("전송 성공");
// else log.error("전송 실패");
// }, Executors.newSingleThreadExecutor());
// return "ok";
// }

private List<List<Message>> getChunkMessages(Map<Notice, List<CrawlingData>> filterNoticeCrawlingGroup,
Set<Subscribe> subscribeSet,
Map<Long, List<Device>> userDeviceGroup) {
Expand Down

0 comments on commit 94f67cd

Please sign in to comment.