Skip to content

Commit

Permalink
Get reverse history and set scheduled event task ID properly (#246)
Browse files Browse the repository at this point in the history
Co-authored-by: feedmeapples <aksenov.ro@outlook.com>
Co-authored-by: Ruslan <11838981+feedmeapples@users.noreply.github.com>
  • Loading branch information
3 people committed Jun 21, 2023
1 parent 2113028 commit 30704e3
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions workflow/workflow_commands.go
Expand Up @@ -1257,7 +1257,7 @@ func getResetEventIDByType(ctx context.Context, c *cli.Context, resetType, names
// Returns event id of the last completed task or id of the next event after scheduled task.
func getLastWorkflowTaskEventID(ctx context.Context, namespace, wid, rid string, frontendClient workflowservice.WorkflowServiceClient) (resetBaseRunID string, workflowTaskEventID int64, err error) {
resetBaseRunID = rid
req := &workflowservice.GetWorkflowExecutionHistoryRequest{
req := &workflowservice.GetWorkflowExecutionHistoryReverseRequest{
Namespace: namespace,
Execution: &commonpb.WorkflowExecution{
WorkflowId: wid,
Expand All @@ -1268,14 +1268,16 @@ func getLastWorkflowTaskEventID(ctx context.Context, namespace, wid, rid string,
}

for {
resp, err := frontendClient.GetWorkflowExecutionHistory(ctx, req)
resp, err := frontendClient.GetWorkflowExecutionHistoryReverse(ctx, req)
if err != nil {
return "", 0, printErrorAndReturn("GetWorkflowExecutionHistory failed", err)
}
for _, e := range resp.GetHistory().GetEvents() {
if e.GetEventType() == enumspb.EVENT_TYPE_WORKFLOW_TASK_COMPLETED {
workflowTaskEventID = e.GetEventId()
break
} else if e.GetEventType() == enumspb.EVENT_TYPE_WORKFLOW_TASK_SCHEDULED {
// if there is no task completed event, set it to first scheduled event + 1
workflowTaskEventID = e.GetEventId() + 1
}
}
Expand Down

0 comments on commit 30704e3

Please sign in to comment.