83
}
84
}
86
}
88
>
if len(currentBatch) == 0 {
89
>
return true
90
>
}
91
93
>
for _, event := range history {
94
>
switch event.GetName() {
95
>
case enumspb.EVENT_TYPE_WORKFLOW_TASK_SCHEDULED.String():
96
>
hasPendingWorkflowTask = true
97
case enumspb.EVENT_TYPE_WORKFLOW_TASK_COMPLETED.String(),
98
enumspb.EVENT_TYPE_WORKFLOW_TASK_FAILED.String(),
100
>
hasPendingWorkflowTask = false
101
}
102
}
104
>
return false
105
>
}
106
>
if currentBatch[len(currentBatch)-1].GetName() == enumspb.EVENT_TYPE_WORKFLOW_TASK_SCHEDULED.String() {
107
return false
108
}
109
>
if currentBatch[0].GetName() == enumspb.EVENT_TYPE_WORKFLOW_TASK_COMPLETED.String() {
history_event_util.go
110
>
return len(currentBatch) == 1
111
>
}
112
>
return true
113
}
114
115
// Setup workflow task model
117
>
workflowTaskSchedule := NewHistoryEventVertex(enumspb.EVENT_TYPE_WORKFLOW_TASK_SCHEDULED.String())
118
>
workflowTaskSchedule.SetDataFunc(func(input ...any) any {
119
>
lastGeneratedEvent := input[1].(*historypb.HistoryEvent)
120
>
eventID := lastGeneratedEvent.GetEventId() + 1
121
>
version := input[2].(int64)
122
>
historyEvent := getDefaultHistoryEvent(eventID, version)
123
>
historyEvent.EventType = enumspb.EVENT_TYPE_WORKFLOW_TASK_SCHEDULED
124
>
historyEvent.Attributes = &historypb.HistoryEvent_WorkflowTaskScheduledEventAttributes{WorkflowTaskScheduledEventAttributes: &historypb.WorkflowTaskScheduledEventAttributes{
125
>
TaskQueue: &taskqueuepb.TaskQueue{
126
>
Name: taskQueue,
127
>
Kind: enumspb.TASK_QUEUE_KIND_NORMAL,
128
>
},
129
>
StartToCloseTimeout: durationpb.New(timeout),
130
>
Attempt: workflowTaskAttempts,
131
>
}}
132
>
return historyEvent
133
>
})
134
>
workflowTaskStart := NewHistoryEventVertex(enumspb.EVENT_TYPE_WORKFLOW_TASK_STARTED.String())
135
>
workflowTaskStart.SetIsStrictOnNextVertex(true)
136
>
workflowTaskStart.SetDataFunc(func(input ...any) any {
137
>
lastEvent := input[0].(*historypb.HistoryEvent)
138
>
lastGeneratedEvent := input[1].(*historypb.HistoryEvent)
139
>
eventID := lastGeneratedEvent.GetEventId() + 1
140
>
version := input[2].(int64)
141
>
historyEvent := getDefaultHistoryEvent(eventID, version)
142
>
historyEvent.EventType = enumspb.EVENT_TYPE_WORKFLOW_TASK_STARTED
143
>
historyEvent.Attributes = &historypb.HistoryEvent_WorkflowTaskStartedEventAttributes{WorkflowTaskStartedEventAttributes: &historypb.WorkflowTaskStartedEventAttributes{
144
>
ScheduledEventId: lastEvent.EventId,
145
>
Identity: identity,
146
>
RequestId: uuid.NewString(),
147
>
}}
148
>
return historyEvent
149
>
})
150
>
workflowTaskFail := NewHistoryEventVertex(enumspb.EVENT_TYPE_WORKFLOW_TASK_FAILED.String())
151
>
workflowTaskFail.SetDataFunc(func(input ...any) any {
152
>
lastEvent := input[0].(*historypb.HistoryEvent)
153
>
lastGeneratedEvent := input[1].(*historypb.HistoryEvent)
154
>
eventID := lastGeneratedEvent.GetEventId() + 1
155
>
version := input[2].(int64)
156
>
historyEvent := getDefaultHistoryEvent(eventID, version)
157
>
historyEvent.EventType = enumspb.EVENT_TYPE_WORKFLOW_TASK_FAILED
158
>
historyEvent.Attributes = &historypb.HistoryEvent_WorkflowTaskFailedEventAttributes{WorkflowTaskFailedEventAttributes: &historypb.WorkflowTaskFailedEventAttributes{
159
>
ScheduledEventId: lastEvent.GetWorkflowTaskStartedEventAttributes().ScheduledEventId,
160
>
StartedEventId: lastEvent.EventId,
161
>
Cause: enumspb.WORKFLOW_TASK_FAILED_CAUSE_UNHANDLED_COMMAND,
162
>
Identity: identity,
163
>
ForkEventVersion: version,
164
>
}}
165
>
return historyEvent
166
>
})
167
>
workflowTaskTimedOut := NewHistoryEventVertex(enumspb.EVENT_TYPE_WORKFLOW_TASK_TIMED_OUT.String())
168
>
workflowTaskTimedOut.SetDataFunc(func(input ...any) any {
169
>
lastEvent := input[0].(*historypb.HistoryEvent)
170
>
lastGeneratedEvent := input[1].(*historypb.HistoryEvent)
171
>
eventID := lastGeneratedEvent.GetEventId() + 1
172
>
version := input[2].(int64)
173
>
historyEvent := getDefaultHistoryEvent(eventID, version)
174
>
historyEvent.EventType = enumspb.EVENT_TYPE_WORKFLOW_TASK_TIMED_OUT
175
>
historyEvent.Attributes = &historypb.HistoryEvent_WorkflowTaskTimedOutEventAttributes{WorkflowTaskTimedOutEventAttributes: &historypb.WorkflowTaskTimedOutEventAttributes{
176
>
ScheduledEventId: lastEvent.GetWorkflowTaskStartedEventAttributes().ScheduledEventId,
177
>
StartedEventId: lastEvent.EventId,
178
>
TimeoutType: enumspb.TIMEOUT_TYPE_SCHEDULE_TO_START,
179
>
}}
180
>
return historyEvent
181
>
})
182
>
workflowTaskComplete := NewHistoryEventVertex(enumspb.EVENT_TYPE_WORKFLOW_TASK_COMPLETED.String())
183
>
workflowTaskComplete.SetDataFunc(func(input ...any) any {
184
>
lastEvent := input[0].(*historypb.HistoryEvent)
185
>
lastGeneratedEvent := input[1].(*historypb.HistoryEvent)
186
>
eventID := lastGeneratedEvent.GetEventId() + 1
187
>
version := input[2].(int64)
188
>
historyEvent := getDefaultHistoryEvent(eventID, version)
189
>
historyEvent.EventType = enumspb.EVENT_TYPE_WORKFLOW_TASK_COMPLETED
190
>
historyEvent.Attributes = &historypb.HistoryEvent_WorkflowTaskCompletedEventAttributes{WorkflowTaskCompletedEventAttributes: &historypb.WorkflowTaskCompletedEventAttributes{
191
>
ScheduledEventId: lastEvent.GetWorkflowTaskStartedEventAttributes().ScheduledEventId,
192
>
StartedEventId: lastEvent.EventId,
193
>
Identity: identity,
194
>
BinaryChecksum: checksum,
195
>
}}
196
>
return historyEvent
197
>
})
198
>
workflowTaskComplete.SetIsStrictOnNextVertex(true)
199
>
workflowTaskComplete.SetMaxNextVertex(2)
200
>
workflowTaskScheduleToStart := NewHistoryEventEdge(workflowTaskSchedule, workflowTaskStart)
201
>
workflowTaskStartToComplete := NewHistoryEventEdge(workflowTaskStart, workflowTaskComplete)
202
>
workflowTaskStartToFail := NewHistoryEventEdge(workflowTaskStart, workflowTaskFail)
203
>
workflowTaskStartToTimedOut := NewHistoryEventEdge(workflowTaskStart, workflowTaskTimedOut)
204
>
workflowTaskFailToSchedule := NewHistoryEventEdge(workflowTaskFail, workflowTaskSchedule)
205
>
workflowTaskFailToSchedule.SetCondition(notPendingWorkflowTask)
206
>
workflowTaskTimedOutToSchedule := NewHistoryEventEdge(workflowTaskTimedOut, workflowTaskSchedule)
207
>
workflowTaskTimedOutToSchedule.SetCondition(notPendingWorkflowTask)
208
>
historyEventModel.AddEdge(workflowTaskScheduleToStart, workflowTaskStartToComplete, workflowTaskStartToFail, workflowTaskStartToTimedOut,
209
>
workflowTaskFailToSchedule, workflowTaskTimedOutToSchedule)
210
>
211
>
// Setup workflow model
212
>
workflowModel := NewHistoryEventModel()
213
>
214
>
workflowStart := NewHistoryEventVertex(enumspb.EVENT_TYPE_WORKFLOW_EXECUTION_STARTED.String())
215
>
workflowStart.SetDataFunc(func(input ...any) any {
216
>
historyEvent := getDefaultHistoryEvent(1, defaultVersion)
217
>
historyEvent.EventType = enumspb.EVENT_TYPE_WORKFLOW_EXECUTION_STARTED
218
>
historyEvent.Attributes = &historypb.HistoryEvent_WorkflowExecutionStartedEventAttributes{WorkflowExecutionStartedEventAttributes: &historypb.WorkflowExecutionStartedEventAttributes{
219
>
WorkflowType: &commonpb.WorkflowType{
220
>
Name: workflowType,
221
>
},
222
>
TaskQueue: &taskqueuepb.TaskQueue{
223
>
Name: taskQueue,
224
>
Kind: enumspb.TASK_QUEUE_KIND_NORMAL,
225
>
},
226
>
WorkflowExecutionTimeout: durationpb.New(timeout),
227
>
WorkflowRunTimeout: durationpb.New(timeout),
228
>
WorkflowTaskTimeout: durationpb.New(timeout),
229
>
Identity: identity,
230
>
FirstExecutionRunId: uuid.NewString(),
231
>
Attempt: 1,
232
>
}}
233
>
return historyEvent
234
>
})
235
>
workflowSignal := NewHistoryEventVertex(enumspb.EVENT_TYPE_WORKFLOW_EXECUTION_SIGNALED.String())
236
>
workflowSignal.SetDataFunc(func(input ...any) any {
237
lastGeneratedEvent := input[1].(*historypb.HistoryEvent)
238
eventID := lastGeneratedEvent.GetEventId() + 1