Skip to content

Commit 5954d1b

Browse files
committed
get workflow steps
1 parent 25b982f commit 5954d1b

File tree

2 files changed

+62
-14
lines changed

2 files changed

+62
-14
lines changed

dbos/cmd/workflow.go

Lines changed: 61 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,12 @@ var workflowGetCmd = &cobra.Command{
2626
RunE: runWorkflowGet,
2727
}
2828

29-
// Steps command is currently not implemented as the method is internal
30-
// var workflowStepsCmd = &cobra.Command{
31-
// Use: "steps [workflow-id]",
32-
// Short: "List the steps of a workflow",
33-
// Args: cobra.ExactArgs(1),
34-
// RunE: runWorkflowSteps,
35-
// }
29+
var workflowStepsCmd = &cobra.Command{
30+
Use: "steps [workflow-id]",
31+
Short: "List the steps of a workflow",
32+
Args: cobra.ExactArgs(1),
33+
RunE: runWorkflowSteps,
34+
}
3635

3736
var workflowCancelCmd = &cobra.Command{
3837
Use: "cancel [workflow-id]",
@@ -59,7 +58,7 @@ func init() {
5958
// Add subcommands to workflow
6059
workflowCmd.AddCommand(workflowListCmd)
6160
workflowCmd.AddCommand(workflowGetCmd)
62-
// workflowCmd.AddCommand(workflowStepsCmd) // Not implemented - internal method
61+
workflowCmd.AddCommand(workflowStepsCmd)
6362
workflowCmd.AddCommand(workflowCancelCmd)
6463
workflowCmd.AddCommand(workflowResumeCmd)
6564
workflowCmd.AddCommand(workflowForkCmd)
@@ -250,11 +249,60 @@ func runWorkflowGet(cmd *cobra.Command, args []string) error {
250249
return nil
251250
}
252251

253-
// Steps function is not implemented as the method is internal
254-
// func runWorkflowSteps(cmd *cobra.Command, args []string) error {
255-
// // Implementation would go here
256-
// return nil
257-
// }
252+
func runWorkflowSteps(cmd *cobra.Command, args []string) error {
253+
workflowID := args[0]
254+
255+
// Get database URL
256+
dbURL, err := getDBURL(cmd)
257+
if err != nil {
258+
return err
259+
}
260+
261+
// Create DBOS context
262+
ctx, err := createDBOSContext(dbURL)
263+
if err != nil {
264+
return err
265+
}
266+
267+
// Get workflow steps
268+
steps, err := dbos.GetWorkflowSteps(ctx, workflowID)
269+
if err != nil {
270+
return fmt.Errorf("failed to get workflow steps: %w", err)
271+
}
272+
273+
// Ensure we have a non-nil slice for JSON output
274+
if steps == nil {
275+
steps = []dbos.StepInfo{}
276+
}
277+
278+
// Output results
279+
if jsonOutput {
280+
return outputJSON(steps)
281+
}
282+
283+
// Pretty print for non-JSON output
284+
if len(steps) == 0 {
285+
logger.Info("No steps found for workflow", "id", workflowID)
286+
return nil
287+
}
288+
289+
fmt.Printf("Steps for workflow %s:\n\n", workflowID)
290+
for _, step := range steps {
291+
fmt.Printf("Step %d: %s\n", step.StepID, step.StepName)
292+
if step.Output != nil {
293+
fmt.Printf(" Output: %v\n", step.Output)
294+
}
295+
if step.Error != nil {
296+
fmt.Printf(" Error: %v\n", step.Error)
297+
}
298+
if step.ChildWorkflowID != "" {
299+
fmt.Printf(" Child Workflow: %s\n", step.ChildWorkflowID)
300+
}
301+
fmt.Println()
302+
}
303+
304+
return nil
305+
}
258306

259307
func runWorkflowCancel(cmd *cobra.Command, args []string) error {
260308
workflowID := args[0]

dbos/dbos.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func processConfig(inputConfig *Config) (*Config, error) {
5353
return nil, fmt.Errorf("missing required config field: appName")
5454
}
5555
if inputConfig.AdminServerPort == 0 {
56-
inputConfig.AdminServerPort = _DEFAULT_ADMIN_SERVER_PORT
56+
inputConfig.AdminServerPort = _DEFAULT_ADMIN_SERVER_PORT
5757
}
5858

5959
dbosConfig := &Config{

0 commit comments

Comments
 (0)