Skip to content

Commit

Permalink
Fixed review comments and unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: parauliya <[email protected]>
  • Loading branch information
parauliya committed Apr 15, 2021
1 parent 5f1b80d commit 246f699
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
15 changes: 10 additions & 5 deletions grpc-server/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,18 @@ func (s *server) ShowWorkflowEvents(req *workflow.GetRequest, stream workflow.Wo
return nil
}

// This function will provide the workflow state on the basis of the state of the actions
// For e.g. : If an action has Tailed or Timeout then the workflow state will also be
// considered as Failed/Timeout. And If an action is successfull then the workflow state
// will be considered as Running until the last action of the workflow is executed successfully.

func getWorkflowState(db db.Database, ctx context.Context, id string) workflow.State {
wfctx, _ := db.GetWorkflowContexts(ctx, id)
if wfctx.CurrentActionState != workflow.State_STATE_SUCCESS {
return wfctx.CurrentActionState
wfCtx, _ := db.GetWorkflowContexts(ctx, id)
if wfCtx.CurrentActionState != workflow.State_STATE_SUCCESS {
return wfCtx.CurrentActionState
} else {
wfacts, _ := db.GetWorkflowActions(ctx, id)
if isLastAction(wfctx, wfacts) {
//wfacts, _ := db.GetWorkflowActions(ctx, id)
if wfCtx.GetCurrentActionIndex() == wfCtx.GetTotalNumberOfActions()-1 {
return workflow.State_STATE_SUCCESS
} else {
return workflow.State_STATE_RUNNING
Expand Down
8 changes: 8 additions & 0 deletions grpc-server/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ func TestGetWorkflow(t *testing.T) {
Template: templateID,
Hardware: hw}, nil
},
GetWorkflowContextsFunc: func(ctx context.Context, wfID string) (*workflow.WorkflowContext, error) {
return &workflow.WorkflowContext{
WorkflowId: wfID,
CurrentActionState: workflow.State_STATE_SUCCESS,
CurrentActionIndex: 0,
TotalNumberOfActions: 1,
}, nil
},
GetTemplateFunc: func(ctx context.Context, fields map[string]string, deleted bool) (string, string, string, error) {
return "", "", templateData, nil
},
Expand Down

0 comments on commit 246f699

Please sign in to comment.