diff --git a/server/worker.go b/server/worker.go index 0e210c9..47e4c39 100644 --- a/server/worker.go +++ b/server/worker.go @@ -194,6 +194,7 @@ func updateWorkerTaskStatus(ctx context.Context) { for _, taskStatusRequest := range taskStatusRequests { tsr := taskStatusRequest + taskID := tsr.ID wg.Add(1) go func() { @@ -204,19 +205,19 @@ func updateWorkerTaskStatus(ctx context.Context) { // Find better way to compare errors which where send via websocket if strings.HasSuffix(err.Error(), constants.ErrTaskDoesNotExist.Error()) { // 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 unknown by worker, Failing...", "err", err, "id", ts.Task.ID) - _, err = db.Exec(ctx, "UPDATE tasks SET status = $2, log = log || $3 WHERE id = $1", ts.Task.ID, constants.TASK_STATUS_FAILED, []string{"Task Failed because it is unknown to Assigned Worker"}) + slog.ErrorContext(ctx, "Task is unknown by worker, Failing...", "err", err, "id", taskID) + _, err = db.Exec(ctx, "UPDATE tasks SET status = $2, log = log || $3 WHERE id = $1", taskID, constants.TASK_STATUS_FAILED, []string{"Task Failed because it is unknown to Assigned Worker"}) if err != nil { slog.ErrorContext(ctx, "Updating Failed Task Status", "err", err) return } - slog.Info("Updating task done", "id", ts.Task.ID, "status", constants.TASK_STATUS_FAILED) + slog.Info("Updating task done", "id", taskID, "status", constants.TASK_STATUS_FAILED) return } else if err != nil { 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", taskID, constants.TASK_STATUS_UNKNOWN) if err != nil { slog.ErrorContext(ctx, "Updating Unknown Task Status", "err", err) return @@ -224,7 +225,7 @@ func updateWorkerTaskStatus(ctx context.Context) { return } - _, err = db.Exec(ctx, "UPDATE tasks SET status = $2, log = log || $3 WHERE id = $1", ts.Task.ID, ts.Task.Status, ts.Task.Log) + _, err = db.Exec(ctx, "UPDATE tasks SET status = $2, log = log || $3 WHERE id = $1", taskID, ts.Task.Status, ts.Task.Log) if err != nil { slog.ErrorContext(ctx, "Updating Task Status", "err", err) return @@ -247,7 +248,7 @@ func updateWorkerTaskStatus(ctx context.Context) { // 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) + _, err := rpcServer.Call(ctx, w.Conn, "task-delete", taskID, nil) if err != nil { slog.ErrorContext(ctx, "Deleting Finished Task From Worker", "err", err) return