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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user