-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWishlistNotificationScheduler.java
More file actions
40 lines (32 loc) · 1.38 KB
/
Copy pathWishlistNotificationScheduler.java
File metadata and controls
40 lines (32 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package com.dropit.notification.scheduler;
import com.dropit.drop.entity.Drop;
import com.dropit.drop.repository.DropRepository;
import com.dropit.notification.service.WishlistNotificationService;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.util.List;
@Component
@ConditionalOnProperty(name = "app.worker.enabled", havingValue = "true")
@RequiredArgsConstructor
public class WishlistNotificationScheduler {
private final DropRepository dropRepository;
private final WishlistNotificationService wishlistNotificationService;
@Scheduled(fixedDelay = 60_000)
public void sendUpcomingDropNotifications() {
LocalDateTime now = LocalDateTime.now();
LocalDateTime from = now.plusMinutes(9);
LocalDateTime to = now.plusMinutes(10);
List<Drop> drops =
dropRepository.findAllByVisibleTrueAndOpenAtBetween(from, to);
for (Drop drop : drops) {
wishlistNotificationService.sendToWishlistUsers(
drop.getProduct().getId(),
"판매 시작 임박",
drop.getProduct().getName() + " 상품이 곧 판매 시작됩니다."
);
}
}
}