From 07811f7ac9788c7d079fd31250c6b54a6e3967b6 Mon Sep 17 00:00:00 2001 From: Rodney Osodo Date: Wed, 8 Jan 2025 23:03:46 +0300 Subject: [PATCH] fix(task): add error to task if the task fails Signed-off-by: Rodney Osodo --- manager/service.go | 4 ++++ proplet/wasm.go | 17 ++++++++++++----- task/task.go | 1 + 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/manager/service.go b/manager/service.go index 2276ca1..36a5743 100644 --- a/manager/service.go +++ b/manager/service.go @@ -341,6 +341,10 @@ func (svc *service) updateResultsHandler(ctx context.Context, msg map[string]int t.UpdatedAt = time.Now() t.FinishTime = time.Now() + if errMsg, ok := msg["error"].(string); ok { + t.Error = errMsg + } + if err := svc.tasksDB.Update(ctx, t.ID, t); err != nil { return err } diff --git a/proplet/wasm.go b/proplet/wasm.go index 471ed87..12717a9 100644 --- a/proplet/wasm.go +++ b/proplet/wasm.go @@ -146,13 +146,20 @@ func (w *wazeroRuntime) runOnHostRuntime(ctx context.Context, wasmBinary []byte, } go func(fileName string) { + var payload map[string]interface{} + if err := cmd.Wait(); err != nil { w.logger.Error("failed to wait for command", slog.String("id", id), slog.String("error", err.Error())) - } - - payload := map[string]interface{}{ - "task_id": id, - "results": results.String(), + payload = map[string]interface{}{ + "task_id": id, + "error": err.Error(), + "results": results.String(), + } + } else { + payload = map[string]interface{}{ + "task_id": id, + "results": results.String(), + } } topic := fmt.Sprintf(resultsTopic, w.channelID) diff --git a/task/task.go b/task/task.go index aaec420..c834b4f 100644 --- a/task/task.go +++ b/task/task.go @@ -38,6 +38,7 @@ type Task struct { CLIArgs []string `json:"cli_args"` Inputs []uint64 `json:"inputs,omitempty"` Results any `json:"results,omitempty"` + Error string `json:"error,omitempty"` StartTime time.Time `json:"start_time"` FinishTime time.Time `json:"finish_time"` CreatedAt time.Time `json:"created_at"`