From 5413d2e7aa9d3246c4a36a69316c5a4ac7d9c6a7 Mon Sep 17 00:00:00 2001 From: Samuel Lorch Date: Sat, 11 May 2024 00:53:22 +0200 Subject: [PATCH] Set Health status based on healthcheck status --- server/worker.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/server/worker.go b/server/worker.go index 05d8c20..5204acb 100644 --- a/server/worker.go +++ b/server/worker.go @@ -213,6 +213,21 @@ func updateWorkerTaskStatus(ctx context.Context) { return } + if ts.Task.Type == constants.TASK_TYPE_HEALTHCHECK && (ts.Task.Status == constants.TASK_STATUS_FAILED || ts.Task.Status == constants.TASK_STATUS_SUCCESS) { + var health constants.FileHealth + if ts.Task.Status == constants.TASK_STATUS_SUCCESS { + health = constants.FILE_HEALTH_HEALTHY + } else { + // TODO, not all failures mean the file is damaged, only update on success and track ffmpeg errors in task result data. also remove -xerror and scan for errors manually to see all problems in logs + health = constants.FILE_HEALTH_DAMAGED + } + _, err = db.Exec(ctx, "UPDATE files SET health = $2 WHERE id = $1", ts.Task.FileID, health) + if err != nil { + slog.ErrorContext(ctx, "Error Updating File health", "err", err) + return + } + } + // Tell Worker to Delete Finished Tasks if ts.Task.Status == constants.TASK_STATUS_FAILED || ts.Task.Status == constants.TASK_STATUS_SUCCESS { _, err := rpcServer.Call(ctx, w.Conn, "task-delete", ts.Task.ID, nil) @@ -220,8 +235,6 @@ func updateWorkerTaskStatus(ctx context.Context) { slog.ErrorContext(ctx, "Error Deleting Finished Task From Worker", "err", err) return } - - // TODO Update file health for healthcheck tasks } }()