Skip to content

Commit

Permalink
feat: 발행 실패한 유저 이벤트 재발행 스케줄러 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
jihwan2da committed Feb 2, 2024
1 parent cbeb3b9 commit 3955c0f
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.gloddy.server.batch.messaging.producer.MessagingBatchEventProducer;
import com.gloddy.server.core.error.handler.exception.BatchBusinessException;
import com.gloddy.server.outbox.domain.handler.GroupOutboxEventQueryHandler;
import com.gloddy.server.outbox.domain.handler.UserOutboxEventQueryHandler;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableScheduling;
Expand All @@ -18,21 +19,29 @@ public class MessagingScheduler {

private final MessagingBatchEventProducer messagingBatchEventProducer;
private final GroupOutboxEventQueryHandler groupOutboxEventQueryHandler;
private final UserOutboxEventQueryHandler userOutboxEventQueryHandler;

@Transactional
@Scheduled(cron = "0 * * * * *", zone = "Asia/Seoul")
public void rePublishEvent() {
public void rePublishGroupEvent() {
executeJob(() -> groupOutboxEventQueryHandler.findAllByNotPublished()
.forEach(messagingBatchEventProducer::produceEvent));
.forEach(messagingBatchEventProducer::produceEvent), "group");
}

private void executeJob(Runnable runnable) {
log.info("Messaging rePublishEvent publishGroupEndEvent 스케줄러 시작");
@Transactional
@Scheduled(cron = "0 * * * * *", zone = "Asia/Seoul")
public void rePublishUserEvent() {
executeJob(() -> userOutboxEventQueryHandler.findAllByNotPublished()
.forEach(messagingBatchEventProducer::produceEvent), "user");
}

private void executeJob(Runnable runnable, String domain) {
log.info("Messaging " + domain + " rePublishEvent 스케줄러 시작");
try {
runnable.run();
} catch (Exception e) {
throw new BatchBusinessException(e);
}
log.info("Messaging rePublishEvent publishGroupEndEvent 스케줄러 완료");
log.info("Messaging " + domain + " rePublishEvent 스케줄러 완료");
}
}

0 comments on commit 3955c0f

Please sign in to comment.