33 lines
1.1 KiB
Java
33 lines
1.1 KiB
Java
package SuMoC.backend.scheduling;
|
|
|
|
import SuMoC.backend.trend.services.StatTableUpdateService;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import java.time.LocalDate;
|
|
|
|
@Component
|
|
@RequiredArgsConstructor
|
|
public class ScheduledTasks {
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(ScheduledTasks.class);
|
|
|
|
private final SchedulingProperties properties;
|
|
|
|
private final StatTableUpdateService statTableUpdateService;
|
|
|
|
@Scheduled(cron = "#{@schedulingProperties.calculateWeeklyMobilityStats}")
|
|
public void scheduleCalculateWeeklyMobilityStats() {
|
|
logger.info("Scheduled task triggered: calculateWeeklyMobilityStatsForAllUsers");
|
|
try {
|
|
LocalDate dayOfLastWeek = LocalDate.now().minusDays(7);
|
|
statTableUpdateService.updateWeeklyMobilityStatsForAllUsers(dayOfLastWeek);
|
|
} catch (Exception e) {
|
|
logger.error("Error calculating weekly mobility stats.", e);
|
|
}
|
|
}
|
|
}
|