Skip to content

Commit

Permalink
Fixed #477 : Corrected state for get and get by id command.
Browse files Browse the repository at this point in the history
Signed-off-by: parauliya <[email protected]>
  • Loading branch information
parauliya committed Apr 14, 2021
1 parent a56e5cf commit 5f1b80d
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions grpc-server/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@ import (
wkf "github.com/tinkerbell/tink/workflow"
)

var state = map[int32]workflow.State{
0: workflow.State_STATE_PENDING,
1: workflow.State_STATE_RUNNING,
2: workflow.State_STATE_FAILED,
3: workflow.State_STATE_TIMEOUT,
4: workflow.State_STATE_SUCCESS,
}

const errFailedToGetTemplate = "failed to get template with ID %s"

// CreateWorkflow implements workflow.CreateWorkflow
Expand Down Expand Up @@ -115,11 +107,12 @@ func (s *server) GetWorkflow(ctx context.Context, in *workflow.GetRequest) (*wor
if err != nil {
return &workflow.Workflow{}, err
}

wf := &workflow.Workflow{
Id: w.ID,
Template: w.Template,
Hardware: w.Hardware,
State: state[w.State],
State: getWorkflowState(s.db, ctx, in.Id),
Data: data,
}
l := s.logger.With("workflowID", w.ID)
Expand Down Expand Up @@ -181,6 +174,7 @@ func (s *server) ListWorkflows(_ *workflow.Empty, stream workflow.WorkflowServic
Hardware: w.Hardware,
CreatedAt: w.CreatedAt,
UpdatedAt: w.UpdatedAt,
State: getWorkflowState(s.db, stream.Context(), w.ID),
}
return stream.Send(wf)
})
Expand Down Expand Up @@ -279,3 +273,17 @@ func (s *server) ShowWorkflowEvents(req *workflow.GetRequest, stream workflow.Wo
metrics.CacheHits.With(labels).Inc()
return nil
}

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
} else {
wfacts, _ := db.GetWorkflowActions(ctx, id)
if isLastAction(wfctx, wfacts) {
return workflow.State_STATE_SUCCESS
} else {
return workflow.State_STATE_RUNNING
}
}
}

0 comments on commit 5f1b80d

Please sign in to comment.