-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSchedulerConfig.java
More file actions
39 lines (33 loc) · 1.46 KB
/
Copy pathSchedulerConfig.java
File metadata and controls
39 lines (33 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package ch.fhnw.timerecordingbackend.config;
import ch.fhnw.timerecordingbackend.service.BackupService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import java.io.IOException;
/**
* Konfiguration für geplante Aufgaben.
* Führt täglich um 02:00 Uhr automatisch ein Backup über den BackupService aus.
* @author FA
* Code von anderen Teammitgliedern oder Quellen wird durch einzelne Kommentare deklariert
*/
@Configuration
@EnableScheduling
public class SchedulerConfig {
private static final Logger logger = LoggerFactory.getLogger(SchedulerConfig.class);
@Autowired
private BackupService backupService;
// Führt das Backup jeden Tag um 02:00 Uhr nachts aus
@Scheduled(cron = "0 0 2 * * ?") // Sekunde Minute Stunde TagMonat Monat TagWoche
public void performDailyBackup() {
logger.info("Starte geplanten täglichen Backup-Prozess...");
try {
String backupPath = backupService.createBackup();
logger.info("Geplanter täglicher Backup erfolgreich abgeschlossen. Gespeichert unter: {}", backupPath);
} catch (IOException e) {
logger.error("Fehler während des geplanten täglichen Backups: {}", e.getMessage(), e);
}
}
}