Add retry mechanism and failure notifications for nCore/qBittorrent setup

- Implemented a retry mechanism for external calls, allowing up to 3 attempts before failing.
- Enhanced error handling to send failure notifications when setup steps fail, including detailed error messages.
- Updated RunSummary model to include status, error step, and error message fields for better tracking of run outcomes.
- Modified database schema to store failure metadata for runs.
- Updated README.md to reflect changes in error handling and notification behavior.
This commit is contained in:
Zsolt Alföldi
2026-05-07 12:03:00 +02:00
parent 696d0227a3
commit 89835b237c
6 changed files with 268 additions and 41 deletions

View File

@@ -43,3 +43,42 @@ func TestMarkResolvedResolvesManualNeededTorrent(t *testing.T) {
t.Fatalf("expected last_resolved_at %q, got %q", resolvedAt.Format(time.RFC3339), got.LastResolvedAt)
}
}
func TestInsertRunRecordsFailureMetadata(t *testing.T) {
db, err := Open(t.TempDir() + "/state.sqlite")
if err != nil {
t.Fatal(err)
}
defer db.Close()
startedAt := time.Date(2026, 5, 7, 11, 0, 0, 0, time.UTC)
if err := db.InsertRun(model.RunSummary{
StartedAt: startedAt,
Status: "failed",
ErrorStep: "fetch nCore HnR page",
ErrorMessage: "timeout",
DryRun: true,
}); err != nil {
t.Fatal(err)
}
stats, err := db.Stats()
if err != nil {
t.Fatal(err)
}
if stats.LastRun == nil {
t.Fatal("expected last run")
}
if stats.LastRun.Status != "failed" {
t.Fatalf("expected status failed, got %q", stats.LastRun.Status)
}
if stats.LastRun.ErrorStep != "fetch nCore HnR page" {
t.Fatalf("expected error step to be recorded, got %q", stats.LastRun.ErrorStep)
}
if stats.LastRun.ErrorMessage != "timeout" {
t.Fatalf("expected error message to be recorded, got %q", stats.LastRun.ErrorMessage)
}
if !stats.LastRun.DryRun {
t.Fatal("expected dry-run to be recorded")
}
}