Skip to content

Commit

Permalink
ChildWorkflow timeout not communicated to parent execution (#504)
Browse files Browse the repository at this point in the history
* ChildWorkflow timeout not communicated to parent execution

RecordChildWorkflowCompletion is missing handling for child execution
getting timedout event.  This results in a empty decision task getting
created without the ChildWorkflowExecutionTimedOut getting recorded in
history.
  • Loading branch information
samarabbas authored Jan 12, 2018
1 parent 113a644 commit 65e165c
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions common/logging/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const (
TagValueActionChildExecutionFailed = "add-childexecution-failed-event"
TagValueActionChildExecutionCanceled = "add-childexecution-canceled-event"
TagValueActionChildExecutionTerminated = "add-childexecution-terminated-event"
TagValueActionChildExecutionTimedOut = "add-childexecution-timedout-event"
TagValueActionRequestCancelWorkflow = "add-request-cancel-workflow-event"
TagValueActionWorkflowCancelRequested = "add-workflow-execution-cancel-requested-event"
TagValueActionWorkflowCancelFailed = "add-workflow-execution-cancel-failed-event"
Expand Down
25 changes: 25 additions & 0 deletions service/history/historyBuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,15 @@ func (b *historyBuilder) AddChildWorkflowExecutionTerminatedEvent(domain string,
return b.addEventToHistory(event)
}

func (b *historyBuilder) AddChildWorkflowExecutionTimedOutEvent(domain string, execution *workflow.WorkflowExecution,
workflowType *workflow.WorkflowType, initiatedID, startedID int64,
timedOutAttributes *workflow.WorkflowExecutionTimedOutEventAttributes) *workflow.HistoryEvent {
event := b.newChildWorkflowExecutionTimedOutEvent(domain, execution, workflowType, initiatedID, startedID,
timedOutAttributes)

return b.addEventToHistory(event)
}

func (b *historyBuilder) addEventToHistory(event *workflow.HistoryEvent) *workflow.HistoryEvent {
b.history = append(b.history, event)
return event
Expand Down Expand Up @@ -797,6 +806,22 @@ func (b *historyBuilder) newChildWorkflowExecutionTerminatedEvent(domain string,
return historyEvent
}

func (b *historyBuilder) newChildWorkflowExecutionTimedOutEvent(domain string, execution *workflow.WorkflowExecution,
workflowType *workflow.WorkflowType, initiatedID, startedID int64,
timedOutAttributes *workflow.WorkflowExecutionTimedOutEventAttributes) *workflow.HistoryEvent {
historyEvent := b.msBuilder.createNewHistoryEvent(workflow.EventTypeChildWorkflowExecutionTimedOut)
attributes := &workflow.ChildWorkflowExecutionTimedOutEventAttributes{}
attributes.Domain = common.StringPtr(domain)
attributes.TimeoutType = timedOutAttributes.TimeoutType
attributes.WorkflowExecution = execution
attributes.WorkflowType = workflowType
attributes.InitiatedEventId = common.Int64Ptr(initiatedID)
attributes.StartedEventId = common.Int64Ptr(startedID)
historyEvent.ChildWorkflowExecutionTimedOutEventAttributes = attributes

return historyEvent
}

func newDecisionTaskScheduledEventWithInfo(eventID, timestamp int64, taskList string, startToCloseTimeoutSeconds int32,
attempt int64) *workflow.HistoryEvent {
historyEvent := createNewHistoryEvent(eventID, workflow.EventTypeDecisionTaskScheduled, timestamp)
Expand Down
3 changes: 3 additions & 0 deletions service/history/historyEngine.go
Original file line number Diff line number Diff line change
Expand Up @@ -1739,6 +1739,9 @@ func (e *historyEngineImpl) RecordChildExecutionCompleted(completionRequest *h.R
case workflow.EventTypeWorkflowExecutionTerminated:
attributes := completionEvent.WorkflowExecutionTerminatedEventAttributes
msBuilder.AddChildWorkflowExecutionTerminatedEvent(initiatedID, completedExecution, attributes)
case workflow.EventTypeWorkflowExecutionTimedOut:
attributes := completionEvent.WorkflowExecutionTimedOutEventAttributes
msBuilder.AddChildWorkflowExecutionTimedOutEvent(initiatedID, completedExecution, attributes)
}

return nil
Expand Down
23 changes: 23 additions & 0 deletions service/history/mutableStateBuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1620,3 +1620,26 @@ func (e *mutableStateBuilder) AddChildWorkflowExecutionTerminatedEvent(initiated

return nil
}

func (e *mutableStateBuilder) AddChildWorkflowExecutionTimedOutEvent(initiatedID int64,
childExecution *workflow.WorkflowExecution,
attributes *workflow.WorkflowExecutionTimedOutEventAttributes) *workflow.HistoryEvent {
ci, ok := e.GetChildExecutionInfo(initiatedID)
if !ok || ci.StartedID == emptyEventID {
logging.LogInvalidHistoryActionEvent(e.logger, logging.TagValueActionChildExecutionTimedOut, e.GetNextEventID(),
fmt.Sprintf("{InitiatedID: %v, Exist: %v}", initiatedID, ok))
return nil
}

startedEvent, _ := e.getHistoryEvent(ci.StartedEvent)

domain := *startedEvent.ChildWorkflowExecutionStartedEventAttributes.Domain
workflowType := startedEvent.ChildWorkflowExecutionStartedEventAttributes.WorkflowType

if err := e.DeletePendingChildExecution(initiatedID); err == nil {
return e.hBuilder.AddChildWorkflowExecutionTimedOutEvent(domain, childExecution, workflowType, ci.InitiatedID,
ci.StartedID, attributes)
}

return nil
}

0 comments on commit 65e165c

Please sign in to comment.