Mark Tasks Unkown to Assigned Worker as Failed

This commit is contained in:
speatzle 2024-05-21 16:30:01 +02:00
parent c7560b2eaa
commit 971aa40615

View file

@ -2,6 +2,7 @@ package server
import ( import (
"context" "context"
"errors"
"log/slog" "log/slog"
"net/http" "net/http"
"sync" "sync"
@ -199,7 +200,17 @@ func updateWorkerTaskStatus(ctx context.Context) {
defer wg.Done() defer wg.Done()
var ts types.TaskStatus var ts types.TaskStatus
_, err := rpcServer.Call(ctx, w.Conn, "task-status", tsr, &ts) _, err := rpcServer.Call(ctx, w.Conn, "task-status", tsr, &ts)
if err != nil { if errors.Is(err, constants.ErrTaskDoesNotExist) {
// Worker says it does not know of this task, mark it failed so that we don't asks the worker about it again and again
slog.ErrorContext(ctx, "Task is unkown by worker, Failing...", "err", err)
_, err = db.Exec(ctx, "UPDATE tasks SET status = $2, log = log || $3 WHERE id = $1", ts.Task.ID, constants.TASK_STATUS_FAILED, "Task Failed because it is unkown to Assigned Worker")
if err != nil {
slog.ErrorContext(ctx, "Updating Failed Task Status", "err", err)
return
}
} else if err != nil {
slog.ErrorContext(ctx, "Getting Task Status", "err", err) slog.ErrorContext(ctx, "Getting Task Status", "err", err)
_, err = db.Exec(ctx, "UPDATE tasks SET status = $2 WHERE id = $1", ts.Task.ID, constants.TASK_STATUS_UNKNOWN) _, err = db.Exec(ctx, "UPDATE tasks SET status = $2 WHERE id = $1", ts.Task.ID, constants.TASK_STATUS_UNKNOWN)