in common/persistence/workflowExecutionInfo.go [45:165]
func (e *WorkflowExecutionInfo) UpdateWorkflowStateCloseStatus(
state int,
closeStatus int,
) error {
switch e.State {
case WorkflowStateVoid:
// no validation
case WorkflowStateCreated:
switch state {
case WorkflowStateCreated:
if closeStatus != WorkflowCloseStatusNone {
return e.createInvalidStateTransitionErr(e.State, state, closeStatus)
}
case WorkflowStateRunning:
if closeStatus != WorkflowCloseStatusNone {
return e.createInvalidStateTransitionErr(e.State, state, closeStatus)
}
case WorkflowStateCompleted:
if closeStatus != WorkflowCloseStatusTerminated &&
closeStatus != WorkflowCloseStatusTimedOut &&
closeStatus != WorkflowCloseStatusContinuedAsNew {
return e.createInvalidStateTransitionErr(e.State, state, closeStatus)
}
case WorkflowStateZombie:
if closeStatus != WorkflowCloseStatusNone {
return e.createInvalidStateTransitionErr(e.State, state, closeStatus)
}
default:
return &types.InternalServiceError{
Message: fmt.Sprintf("unknown workflow state: %v", state),
}
}
case WorkflowStateRunning:
switch state {
case WorkflowStateCreated:
return e.createInvalidStateTransitionErr(e.State, state, closeStatus)
case WorkflowStateRunning:
if closeStatus != WorkflowCloseStatusNone {
return e.createInvalidStateTransitionErr(e.State, state, closeStatus)
}
case WorkflowStateCompleted:
if closeStatus == WorkflowCloseStatusNone {
return e.createInvalidStateTransitionErr(e.State, state, closeStatus)
}
case WorkflowStateZombie:
if closeStatus != WorkflowCloseStatusNone {
return e.createInvalidStateTransitionErr(e.State, state, closeStatus)
}
default:
return &types.InternalServiceError{
Message: fmt.Sprintf("unknown workflow state: %v", state),
}
}
case WorkflowStateCompleted:
switch state {
case WorkflowStateCreated:
return e.createInvalidStateTransitionErr(e.State, state, closeStatus)
case WorkflowStateRunning:
return e.createInvalidStateTransitionErr(e.State, state, closeStatus)
case WorkflowStateCompleted:
if closeStatus != e.CloseStatus {
return e.createInvalidStateTransitionErr(e.State, state, closeStatus)
}
case WorkflowStateZombie:
return e.createInvalidStateTransitionErr(e.State, state, closeStatus)
default:
return &types.InternalServiceError{
Message: fmt.Sprintf("unknown workflow state: %v", state),
}
}
case WorkflowStateZombie:
switch state {
case WorkflowStateCreated:
if closeStatus != WorkflowCloseStatusNone {
return e.createInvalidStateTransitionErr(e.State, state, closeStatus)
}
case WorkflowStateRunning:
if closeStatus != WorkflowCloseStatusNone {
return e.createInvalidStateTransitionErr(e.State, state, closeStatus)
}
case WorkflowStateCompleted:
if closeStatus == WorkflowCloseStatusNone {
return e.createInvalidStateTransitionErr(e.State, state, closeStatus)
}
case WorkflowStateZombie:
if closeStatus == WorkflowCloseStatusNone {
return e.createInvalidStateTransitionErr(e.State, state, closeStatus)
}
default:
return &types.InternalServiceError{
Message: fmt.Sprintf("unknown workflow state: %v", state),
}
}
default:
return &types.InternalServiceError{
Message: fmt.Sprintf("unknown workflow state: %v", state),
}
}
e.State = state
e.CloseStatus = closeStatus
return nil
}