Skip to content

Commit

Permalink
[Wf-Diagnotics] Update Diagnostics workflow result to provide a compl…
Browse files Browse the repository at this point in the history
…etion signal (cadence-workflow#6635)
  • Loading branch information
sankari165 authored Jan 21, 2025
1 parent fa6580d commit 3ab9c05
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 11 additions & 6 deletions service/worker/diagnostics/parent_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,17 @@ type DiagnosticsStarterWorkflowInput struct {
}

type DiagnosticsStarterWorkflowResult struct {
DiagnosticsResult *DiagnosticsWorkflowResult
DiagnosticsResult *DiagnosticsWorkflowResult
DiagnosticsCompleted bool
}

func (w *dw) DiagnosticsStarterWorkflow(ctx workflow.Context, params DiagnosticsStarterWorkflowInput) (*DiagnosticsStarterWorkflowResult, error) {
var result DiagnosticsWorkflowResult
var diagWfResult DiagnosticsWorkflowResult
workflowResult := DiagnosticsStarterWorkflowResult{
DiagnosticsResult: &diagWfResult,
}
err := workflow.SetQueryHandler(ctx, queryDiagnosticsReport, func() (DiagnosticsStarterWorkflowResult, error) {
return DiagnosticsStarterWorkflowResult{DiagnosticsResult: &result}, nil
return workflowResult, nil
})
if err != nil {
return nil, err
Expand All @@ -74,10 +78,11 @@ func (w *dw) DiagnosticsStarterWorkflow(ctx workflow.Context, params Diagnostics
}
childWfStart = workflow.Now(ctx)

err = future.Get(ctx, &result)
err = future.Get(ctx, &diagWfResult)
if err != nil {
return nil, fmt.Errorf("Workflow Diagnostics failed: %w", err)
}
workflowResult.DiagnosticsCompleted = true
childWfEnd = workflow.Now(ctx)

activityOptions := workflow.ActivityOptions{
Expand All @@ -91,7 +96,7 @@ func (w *dw) DiagnosticsStarterWorkflow(ctx workflow.Context, params Diagnostics
WorkflowID: params.WorkflowID,
RunID: params.RunID,
Identity: params.Identity,
IssueType: getIssueType(result),
IssueType: getIssueType(diagWfResult),
DiagnosticsWorkflowID: childWfExec.ID,
DiagnosticsRunID: childWfExec.RunID,
DiagnosticsStartTime: childWfStart,
Expand All @@ -101,7 +106,7 @@ func (w *dw) DiagnosticsStarterWorkflow(ctx workflow.Context, params Diagnostics
return nil, fmt.Errorf("EmitUsageLogs: %w", err)
}

return &DiagnosticsStarterWorkflowResult{DiagnosticsResult: &result}, nil
return &workflowResult, nil
}

func getIssueType(result DiagnosticsWorkflowResult) string {
Expand Down
2 changes: 2 additions & 0 deletions service/worker/diagnostics/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,12 @@ func (s *diagnosticsWorkflowTestSuite) TestWorkflow() {
s.NoError(s.workflowEnv.GetWorkflowResult(&result))
s.ElementsMatch(timeoutIssues, result.DiagnosticsResult.Timeouts.Issues)
s.ElementsMatch(timeoutRootCause, result.DiagnosticsResult.Timeouts.RootCause)
s.True(result.DiagnosticsCompleted)

queriedResult := s.queryDiagnostics()
s.ElementsMatch(queriedResult.DiagnosticsResult.Timeouts.Issues, result.DiagnosticsResult.Timeouts.Issues)
s.ElementsMatch(queriedResult.DiagnosticsResult.Timeouts.RootCause, result.DiagnosticsResult.Timeouts.RootCause)
s.True(queriedResult.DiagnosticsCompleted)
}

func (s *diagnosticsWorkflowTestSuite) TestWorkflow_Error() {
Expand Down

0 comments on commit 3ab9c05

Please sign in to comment.