Skip to content

Commit

Permalink
put firstEventID as part of nextPageToken (uber#419)
Browse files Browse the repository at this point in the history
  • Loading branch information
yiminc authored Nov 15, 2017
1 parent 7553066 commit b446766
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions service/frontend/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type (

getHistoryContinuationToken struct {
RunID string
FirstEventID int64
NextEventID int64
PersistenceToken []byte
}
Expand Down Expand Up @@ -418,6 +419,7 @@ func (wh *WorkflowHandler) PollForDecisionTask(
persistenceToken,
*matchingResp.WorkflowExecution.RunId,
history,
firstEventID,
nextEventID)
if err != nil {
return nil, wh.error(err, scope)
Expand Down Expand Up @@ -766,6 +768,7 @@ func (wh *WorkflowHandler) GetWorkflowExecutionHistory(
DomainUUID: common.StringPtr(info.ID),
Execution: getRequest.Execution,
})
token.FirstEventID = common.FirstEventID
if err == nil {
token.NextEventID = *response.EventId
token.RunID = *response.RunId
Expand All @@ -792,17 +795,17 @@ func (wh *WorkflowHandler) GetWorkflowExecutionHistory(
RunId: common.StringPtr(token.RunID),
}
history, persistenceToken, err :=
wh.getHistory(info.ID, we, common.FirstEventID, token.NextEventID, *getRequest.MaximumPageSize, token.PersistenceToken)
wh.getHistory(info.ID, we, token.FirstEventID, token.NextEventID, *getRequest.MaximumPageSize, token.PersistenceToken)
if err != nil {
return nil, wh.error(err, scope)
}

nextToken, err := getSerializedGetHistoryToken(persistenceToken, token.RunID, history, token.NextEventID)
nextToken, err := getSerializedGetHistoryToken(persistenceToken, token.RunID, history, token.FirstEventID, token.NextEventID)
if err != nil {
return nil, wh.error(err, scope)
}

return createGetWorkflowExecutionHistoryResponse(history, token.NextEventID, nextToken), nil
return createGetWorkflowExecutionHistoryResponse(history, nextToken), nil
}

// SignalWorkflowExecution is used to send a signal event to running workflow execution. This results in
Expand Down Expand Up @@ -1372,7 +1375,7 @@ func (wh *WorkflowHandler) createPollForDecisionTaskResponse(ctx context.Context
}

func createGetWorkflowExecutionHistoryResponse(
history *gen.History, nextEventID int64, nextPageToken []byte) *gen.GetWorkflowExecutionHistoryResponse {
history *gen.History, nextPageToken []byte) *gen.GetWorkflowExecutionHistoryResponse {
resp := &gen.GetWorkflowExecutionHistoryResponse{}
resp.History = history
resp.NextPageToken = nextPageToken
Expand All @@ -1386,7 +1389,7 @@ func deserializeGetHistoryToken(data []byte) (*getHistoryContinuationToken, erro
return &token, err
}

func getSerializedGetHistoryToken(persistenceToken []byte, runID string, history *gen.History, nextEventID int64) ([]byte, error) {
func getSerializedGetHistoryToken(persistenceToken []byte, runID string, history *gen.History, firstEventID, nextEventID int64) ([]byte, error) {
// create token if there are more events to read
if history == nil {
return nil, nil
Expand All @@ -1395,6 +1398,7 @@ func getSerializedGetHistoryToken(persistenceToken []byte, runID string, history
if len(persistenceToken) > 0 && len(events) > 0 && *events[len(events)-1].EventId < nextEventID-1 {
token := &getHistoryContinuationToken{
RunID: runID,
FirstEventID: firstEventID,
NextEventID: nextEventID,
PersistenceToken: persistenceToken,
}
Expand Down

0 comments on commit b446766

Please sign in to comment.