Skip to content

Commit

Permalink
fix(task): add error to task if the task fails
Browse files Browse the repository at this point in the history
Signed-off-by: Rodney Osodo <[email protected]>
  • Loading branch information
rodneyosodo committed Jan 8, 2025
1 parent 335dc6c commit 07811f7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
4 changes: 4 additions & 0 deletions manager/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
17 changes: 12 additions & 5 deletions proplet/wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit 07811f7

Please sign in to comment.