Skip to content

Commit 7a62ef2

Browse files
committed
http server explicitly stringifies input/outputs
1 parent 630532d commit 7a62ef2

File tree

1 file changed

+41
-10
lines changed

1 file changed

+41
-10
lines changed

dbos/admin_server.go

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ type adminServer struct {
105105
isDeactivated atomic.Int32
106106
}
107107

108-
// workflowStatusToUTC converts a WorkflowStatus to a map with all time fields in UTC
108+
// toListWorkflowResponse converts a WorkflowStatus to a map with all time fields in UTC
109109
// not super ergonomic but the DBOS console excepts unix timestamps
110-
func workflowStatusToUTC(ws WorkflowStatus) map[string]any {
110+
func toListWorkflowResponse(ws WorkflowStatus) (map[string]any, err) {
111111
result := map[string]any{
112112
"WorkflowUUID": ws.ID,
113113
"Status": ws.Status,
@@ -152,7 +152,23 @@ func workflowStatusToUTC(ws WorkflowStatus) map[string]any {
152152
result["StartedAt"] = nil
153153
}
154154

155-
return result
155+
if ws.Input != nil {
156+
bytes, err := json.Marshal(ws.Input)
157+
if err != nil {
158+
return nil, fmt.Errorf("failed to marshal input: %w", err)
159+
}
160+
result["Input"] = string(bytes)
161+
}
162+
163+
if ws.Output != nil {
164+
bytes, err := json.Marshal(ws.Output)
165+
if err != nil {
166+
return nil, fmt.Errorf("failed to marshal output: %w", err)
167+
}
168+
result["Output"] = string(bytes)
169+
}
170+
171+
return result, nil
156172
}
157173

158174
func newAdminServer(ctx *dbosContext, port int) *adminServer {
@@ -295,13 +311,18 @@ func newAdminServer(ctx *dbosContext, port int) *adminServer {
295311
}
296312

297313
// Transform to UTC before encoding
298-
utcWorkflows := make([]map[string]any, len(workflows))
314+
responseWorkflows := make([]map[string]any, len(workflows))
299315
for i, wf := range workflows {
300-
utcWorkflows[i] = workflowStatusToUTC(wf)
316+
responseWorkflows[i], err = toListWorkflowResponse(wf)
317+
if err != nil {
318+
ctx.logger.Error("Error transforming workflow response", "error", err)
319+
http.Error(w, fmt.Sprintf("Failed to format workflow response: %v", err), http.StatusInternalServerError)
320+
return
321+
}
301322
}
302323

303324
w.Header().Set("Content-Type", "application/json")
304-
if err := json.NewEncoder(w).Encode(utcWorkflows); err != nil {
325+
if err := json.NewEncoder(w).Encode(responseWorkflows); err != nil {
305326
ctx.logger.Error("Error encoding workflows response", "error", err)
306327
http.Error(w, fmt.Sprintf("Failed to encode response: %v", err), http.StatusInternalServerError)
307328
}
@@ -327,7 +348,12 @@ func newAdminServer(ctx *dbosContext, port int) *adminServer {
327348
}
328349

329350
// Return the first (and only) workflow, transformed to UTC
330-
workflow := workflowStatusToUTC(workflows[0])
351+
workflow, err := toListWorkflowResponse(workflows[0])
352+
if err != nil {
353+
ctx.logger.Error("Error transforming workflow response", "error", err)
354+
http.Error(w, fmt.Sprintf("Failed to format workflow response: %v", err), http.StatusInternalServerError)
355+
return
356+
}
331357

332358
w.Header().Set("Content-Type", "application/json")
333359
if err := json.NewEncoder(w).Encode(workflow); err != nil {
@@ -365,13 +391,18 @@ func newAdminServer(ctx *dbosContext, port int) *adminServer {
365391
}
366392

367393
// Transform to UNIX timestamps before encoding
368-
utcWorkflows := make([]map[string]any, len(workflows))
394+
responseWorkflows := make([]map[string]any, len(workflows))
369395
for i, wf := range workflows {
370-
utcWorkflows[i] = workflowStatusToUTC(wf)
396+
responseWorkflows[i], err = toListWorkflowResponse(wf)
397+
if err != nil {
398+
ctx.logger.Error("Error transforming workflow response", "error", err)
399+
http.Error(w, fmt.Sprintf("Failed to format workflow response: %v", err), http.StatusInternalServerError)
400+
return
401+
}
371402
}
372403

373404
w.Header().Set("Content-Type", "application/json")
374-
if err := json.NewEncoder(w).Encode(utcWorkflows); err != nil {
405+
if err := json.NewEncoder(w).Encode(responseWorkflows); err != nil {
375406
ctx.logger.Error("Error encoding queued workflows response", "error", err)
376407
http.Error(w, fmt.Sprintf("Failed to encode response: %v", err), http.StatusInternalServerError)
377408
}

0 commit comments

Comments
 (0)