This commit is contained in:
@ -12,6 +12,7 @@ import se.urmo.electricityalert.store.InMemoryPriceStore;
|
|||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@ -31,7 +32,9 @@ public class AlertService {
|
|||||||
// Check every 5 minutes
|
// Check every 5 minutes
|
||||||
@Scheduled(fixedRate = 300_000)
|
@Scheduled(fixedRate = 300_000)
|
||||||
public void checkPrices() {
|
public void checkPrices() {
|
||||||
LocalDateTime oneHourLater = LocalDateTime.now().withMinute(0).withSecond(0).plusHours(1);
|
LocalDateTime oneHourLater = LocalDateTime.now()
|
||||||
|
.truncatedTo(ChronoUnit.HOURS)
|
||||||
|
.plusHours(1);
|
||||||
ElectricityPrice price = store.get(oneHourLater);
|
ElectricityPrice price = store.get(oneHourLater);
|
||||||
log.debug("Checking price at {} ({})", oneHourLater, price);
|
log.debug("Checking price at {} ({})", oneHourLater, price);
|
||||||
if (price != null && price.price().compareTo(threshold) < 0 && !store.alreadyNotified(oneHourLater)) {
|
if (price != null && price.price().compareTo(threshold) < 0 && !store.alreadyNotified(oneHourLater)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user