Handle self-invocation in PostService

This commit is contained in:
Tim
2025-08-11 11:11:11 +08:00
parent 908df079e0
commit 4b987f894d

View File

@@ -43,8 +43,8 @@ import java.util.HashSet;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import jakarta.annotation.PostConstruct; import org.springframework.context.event.EventListener;
@Slf4j @Slf4j
@Service @Service
@@ -108,8 +108,8 @@ public class PostService {
this.publishMode = publishMode; this.publishMode = publishMode;
} }
@PostConstruct @EventListener(ApplicationReadyEvent.class)
private void rescheduleLotteries() { public void rescheduleLotteries() {
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
for (LotteryPost lp : lotteryPostRepository.findByEndTimeAfterAndWinnersIsEmpty(now)) { for (LotteryPost lp : lotteryPostRepository.findByEndTimeAfterAndWinnersIsEmpty(now)) {
ScheduledFuture<?> future = taskScheduler.schedule( ScheduledFuture<?> future = taskScheduler.schedule(