implemented scheduled tasks and notification scheduler so that whole chain task -> detected trends -> scheduled notification -> notification sent by worker is working

This commit is contained in:
2026-01-13 18:07:15 +01:00
parent 521a4ba957
commit 11ce10a8d8
14 changed files with 134 additions and 79 deletions
@@ -2,6 +2,7 @@ package SuMoC.backend.scheduling;
import SuMoC.backend.notification.services.NotificationWorker;
import SuMoC.backend.trend.services.StatTableUpdateService;
import SuMoC.backend.trend.services.TrendNotificationService;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -20,18 +21,20 @@ public class ScheduledTasks {
private final StatTableUpdateService statTableUpdateService;
private final TrendNotificationService trendNotificationService;
private final NotificationWorker notificationWorker;
/**
* Calculate weekly mobility stats for all users and generate corresponding notifications.
*/
@Scheduled(cron = "#{@schedulingProperties.calculateWeeklyMobilityStats}")
public void scheduleCalculateWeeklyMobilityStats() {
@Scheduled(cron = "#{@schedulingProperties.notifyWeeklyMobilityStats}")
public void scheduleNotifyWeeklyMobilityStats() {
logger.info("Scheduled task triggered: calculateWeeklyMobilityStatsForAllUsers");
try {
LocalDate dayOfLastWeek = LocalDate.now().minusDays(7);
LocalDate dayOfLastWeek = LocalDate.now().minusWeeks(1);
statTableUpdateService.updateWeeklyMobilityStatsForAllUsers(dayOfLastWeek);
// TODO generate and queue notifications about new stats being available
trendNotificationService.detectAndNotifyTrends(dayOfLastWeek.getYear(), dayOfLastWeek.get(java.time.temporal.IsoFields.WEEK_OF_WEEK_BASED_YEAR));
} catch (Exception e) {
logger.error("Error calculating weekly mobility stats.", e);
}