mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-18 04:50:57 +08:00
Reschedule lottery finalization on startup
This commit is contained in:
@@ -42,6 +42,8 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
|
||||
@Service
|
||||
public class PostService {
|
||||
private final PostRepository postRepository;
|
||||
@@ -100,6 +102,20 @@ public class PostService {
|
||||
this.publishMode = publishMode;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
private void rescheduleLotteries() {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
for (LotteryPost lp : lotteryPostRepository.findByEndTimeAfterAndWinnersIsEmpty(now)) {
|
||||
ScheduledFuture<?> future = taskScheduler.schedule(
|
||||
() -> finalizeLottery(lp.getId()),
|
||||
java.util.Date.from(lp.getEndTime().atZone(ZoneId.systemDefault()).toInstant()));
|
||||
scheduledFinalizations.put(lp.getId(), future);
|
||||
}
|
||||
for (LotteryPost lp : lotteryPostRepository.findByEndTimeBeforeAndWinnersIsEmpty(now)) {
|
||||
finalizeLottery(lp.getId());
|
||||
}
|
||||
}
|
||||
|
||||
public PublishMode getPublishMode() {
|
||||
return publishMode;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user