MCPcopy Create free account
hub / github.com/astercloud/aster / Execute

Method Execute

server/handlers/workflow.go:346–416  ·  view source on GitHub ↗

Execute executes a workflow

(c *gin.Context)

Source from the content-addressed store, hash-verified

344
345// Execute executes a workflow
346func (h *WorkflowHandler) Execute(c *gin.Context) {
347 ctx := c.Request.Context()
348 id := c.Param("id")
349
350 var req struct {
351 Context map[string]any `json:"context"`
352 Metadata map[string]any `json:"metadata"`
353 }
354
355 if err := c.ShouldBindJSON(&req); err != nil {
356 req.Context = make(map[string]any)
357 }
358
359 // Check if workflow exists
360 var workflow WorkflowRecord
361 if err := (*h.store).Get(ctx, "workflows", id, &workflow); err != nil {
362 if errors.Is(err, store.ErrNotFound) {
363 c.JSON(http.StatusNotFound, gin.H{
364 "success": false,
365 "error": gin.H{
366 "code": "not_found",
367 "message": "Workflow not found",
368 },
369 })
370 return
371 }
372 c.JSON(http.StatusInternalServerError, gin.H{
373 "success": false,
374 "error": gin.H{
375 "code": "internal_error",
376 "message": "Failed to get workflow: " + err.Error(),
377 },
378 })
379 return
380 }
381
382 // Create execution record
383 execution := &WorkflowExecution{
384 ID: uuid.New().String(),
385 WorkflowID: id,
386 Status: "pending",
387 StartedAt: time.Now(),
388 Context: req.Context,
389 Logs: []ExecutionLog{},
390 Metadata: req.Metadata,
391 }
392
393 if err := (*h.store).Set(ctx, "workflow_executions", execution.ID, execution); err != nil {
394 c.JSON(http.StatusInternalServerError, gin.H{
395 "success": false,
396 "error": gin.H{
397 "code": "internal_error",
398 "message": "Failed to create execution: " + err.Error(),
399 },
400 })
401 return
402 }
403

Callers

nothing calls this directly

Calls 7

InfoFunction · 0.92
JSONMethod · 0.80
ContextMethod · 0.65
GetMethod · 0.65
ErrorMethod · 0.65
SetMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected