Notify when prune completes

This commit is contained in:
Mikei386
2026-06-22 21:19:41 +02:00
parent 91089328ce
commit 99e2753c10
8 changed files with 45 additions and 11 deletions
+15
View File
@@ -27,3 +27,18 @@ func TestNotificationTitleIncludesRepositoryAndStatus(t *testing.T) {
t.Fatalf("title = %q", title)
}
}
func TestNotificationMessageIncludesPruneSummary(t *testing.T) {
started := time.Date(2026, 6, 22, 3, 0, 0, 0, time.UTC)
finished := started.Add(42 * time.Second)
run := model.Run{TaskType: "prune", Status: "success", StartedAt: &started, FinishedAt: &finished, Message: "prune completed"}
message := notificationMessage("Repository-Bereinigung", "LV-426", run, finished)
for _, expected := range []string{"🧹 Prune-Zusammenfassung", "📦 Repository: LV-426", "🗂️ Job: Repository-Bereinigung", "⏱️ Dauer: 42 Sekunden", "🔐 Ziel: Restic Repository", "✅ Status: Erfolgreich"} {
if !strings.Contains(message, expected) {
t.Errorf("message %q does not contain %q", message, expected)
}
}
if strings.Contains(message, "⚠️ Details: prune completed") {
t.Fatalf("message contains redundant prune completion details: %q", message)
}
}
+14 -3
View File
@@ -427,8 +427,14 @@ func (s *Service) ForceUnlockRepository(ctx context.Context, repoID string) erro
return s.restic.ForceUnlock(ctx, mounted.Repository)
}
func (s *Service) execute(ctx context.Context, run model.Run) model.Run {
func (s *Service) execute(ctx context.Context, run model.Run) (result model.Run) {
ctx = restic.WithRunID(ctx, run.ID)
maintenanceRepoName := ""
defer func() {
if result.TaskType == "prune" && (result.Status == "success" || result.Status == "warning" || result.Status == "failed") {
go s.notify("Repository-Bereinigung", maintenanceRepoName, result)
}
}()
if run.TaskType == "backup" {
return s.executeBackup(ctx, run)
}
@@ -442,6 +448,7 @@ func (s *Service) execute(ctx context.Context, run model.Run) model.Run {
if !ok {
return failed(run, "validation", "repository no longer exists")
}
maintenanceRepoName = repo.Name
live := run
appendLiveLog(&live, strings.ToUpper(run.TaskType)+" wird vorbereitet")
s.updateActive(live)
@@ -817,7 +824,11 @@ func notificationMessage(name, repository string, run model.Run, now time.Time)
if status == "" {
status = run.Status
}
lines := []string{"📊 Backup-Zusammenfassung", ""}
summaryTitle := map[string]string{"backup": "📊 Backup-Zusammenfassung", "rsync": "📊 Rsync-Zusammenfassung", "restore": "📊 Restore-Zusammenfassung", "prune": "🧹 Prune-Zusammenfassung", "check": "🔎 Prüfungs-Zusammenfassung"}[run.TaskType]
if summaryTitle == "" {
summaryTitle = "📊 URBM-Zusammenfassung"
}
lines := []string{summaryTitle, ""}
if repository != "" {
lines = append(lines, "📦 Repository: "+repository)
}
@@ -852,7 +863,7 @@ func notificationMessage(name, repository string, run model.Run, now time.Time)
}
}
lines = append(lines, "", "🔐 Ziel: "+notificationTargetLabel(run.TaskType), statusIcon(run.Status)+" Status: "+status)
if run.Message != "" && run.Message != "backup completed" && run.Message != "rsync completed" {
if run.Message != "" && run.Message != run.TaskType+" completed" {
lines = append(lines, "⚠️ Details: "+run.Message)
}
return strings.Join(lines, "\n")