add notification cleanup task

This commit is contained in:
2026-01-13 17:04:17 +01:00
parent bc3dd9b59b
commit 521a4ba957
5 changed files with 64 additions and 0 deletions
@@ -22,17 +22,24 @@ public class ScheduledTasks {
private final NotificationWorker notificationWorker;
/**
* Calculate weekly mobility stats for all users and generate corresponding notifications.
*/
@Scheduled(cron = "#{@schedulingProperties.calculateWeeklyMobilityStats}")
public void scheduleCalculateWeeklyMobilityStats() {
logger.info("Scheduled task triggered: calculateWeeklyMobilityStatsForAllUsers");
try {
LocalDate dayOfLastWeek = LocalDate.now().minusDays(7);
statTableUpdateService.updateWeeklyMobilityStatsForAllUsers(dayOfLastWeek);
// TODO generate and queue notifications about new stats being available
} catch (Exception e) {
logger.error("Error calculating weekly mobility stats.", e);
}
}
/**
* Run the notification worker to process pending notifications.
*/
@Scheduled(cron = "#{@schedulingProperties.runNotificationWorker}")
public void scheduleRunNotificationWorker() {
logger.info("Scheduled task triggered: runNotificationWorker");
@@ -42,4 +49,17 @@ public class ScheduledTasks {
logger.error("Error running notification worker.", e);
}
}
/**
* Clean up old notifications from the database.
*/
@Scheduled(cron = "#{@schedulingProperties.cleanUpOldNotifications}")
public void scheduleCleanUpOldNotifications() {
logger.info("Scheduled task triggered: cleanUpOldNotifications");
try {
notificationWorker.cleanUpOldNotifications();
} catch (Exception e) {
logger.error("Error cleaning up old notifications.", e);
}
}
}