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
@@ -0,0 +1,31 @@
package SuMoC.backend.trend.services;
import SuMoC.backend.notification.enums.NotificationType;
import SuMoC.backend.notification.services.NotificationSchedulerService;
import SuMoC.backend.trend.config.TrendProperties;
import SuMoC.backend.trend.enums.StatAttribute;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
@Service
@RequiredArgsConstructor
public class TrendNotificationService {
private final TrendDetectorService trendDetectorService;
private final NotificationSchedulerService notificationSchedulerService;
private final TrendProperties trendProperties;
/**
* Detects trends for the given year and week number and sends notifications to users.
*/
public void detectAndNotifyTrends(int year, int weekNumber) {
// TODO for now we only consider CAR_DISTANCE, but this can be extended later
var detectedTrends = trendDetectorService.detectWeeklyTrends(year, weekNumber, StatAttribute.CAR_DISTANCE);
// we create a new list so the java type system is happy
notificationSchedulerService.scheduleAll(new ArrayList<>(detectedTrends), NotificationType.TREND, trendProperties.getEarliestTrendNotificationTimeOfDay());
}
}