add notification cleanup task
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user