@@ -72,7 +72,7 @@ func (e *executor) ExecuteTask(ctx context.Context, t *task.Workflow) ([]history
72
72
}
73
73
74
74
// Always pad the received events with WorkflowTaskStarted/Finished events to indicate the execution
75
- events := []history.Event {history .NewHistoryEvent (e .clock .Now (), history .EventType_WorkflowTaskStarted , - 1 , & history.WorkflowTaskStartedAttributes {})}
75
+ events := []history.Event {history .NewHistoryEvent (e .clock .Now (), history .EventType_WorkflowTaskStarted , & history.WorkflowTaskStartedAttributes {})}
76
76
events = append (events , t .NewEvents ... )
77
77
78
78
// Execute new events received from the backend
@@ -87,7 +87,7 @@ func (e *executor) ExecuteTask(ctx context.Context, t *task.Workflow) ([]history
87
87
events = append (events , newCommandEvents ... )
88
88
89
89
// Execution of this task is finished, add event to history
90
- events = append (events , history .NewHistoryEvent (e .clock .Now (), history .EventType_WorkflowTaskFinished , - 1 , & history.WorkflowTaskFinishedAttributes {}))
90
+ events = append (events , history .NewHistoryEvent (e .clock .Now (), history .EventType_WorkflowTaskFinished , & history.WorkflowTaskFinishedAttributes {}))
91
91
92
92
e .lastEventID = events [len (events )- 1 ].ID
93
93
@@ -204,7 +204,7 @@ func (e *executor) handleWorkflowTaskStarted(event history.Event, a *history.Wor
204
204
}
205
205
206
206
func (e * executor ) handleActivityScheduled (event history.Event , a * history.ActivityScheduledAttributes ) error {
207
- c := e .workflowState .removeCommandByEventID (event .EventID )
207
+ c := e .workflowState .removeCommandByEventID (event .ScheduleEventID )
208
208
if c != nil {
209
209
// Ensure the same activity is scheduled again
210
210
ca := c .Attr .(* command.ScheduleActivityTaskCommandAttr )
@@ -217,52 +217,52 @@ func (e *executor) handleActivityScheduled(event history.Event, a *history.Activ
217
217
}
218
218
219
219
func (e * executor ) handleActivityCompleted (event history.Event , a * history.ActivityCompletedAttributes ) error {
220
- f , ok := e .workflowState .pendingFutures [event .EventID ]
220
+ f , ok := e .workflowState .pendingFutures [event .ScheduleEventID ]
221
221
if ! ok {
222
222
return nil
223
223
}
224
224
225
- e .workflowState .removeCommandByEventID (event .EventID )
225
+ e .workflowState .removeCommandByEventID (event .ScheduleEventID )
226
226
f .Set (a .Result , nil )
227
227
228
228
return e .workflow .Continue (e .workflowCtx )
229
229
}
230
230
231
231
func (e * executor ) handleActivityFailed (event history.Event , a * history.ActivityFailedAttributes ) error {
232
- f , ok := e .workflowState .pendingFutures [event .EventID ]
232
+ f , ok := e .workflowState .pendingFutures [event .ScheduleEventID ]
233
233
if ! ok {
234
234
return errors .New ("no pending future found for activity failed event" )
235
235
}
236
236
237
- e .workflowState .removeCommandByEventID (event .EventID )
237
+ e .workflowState .removeCommandByEventID (event .ScheduleEventID )
238
238
239
239
f .Set (nil , errors .New (a .Reason ))
240
240
241
241
return e .workflow .Continue (e .workflowCtx )
242
242
}
243
243
244
244
func (e * executor ) handleTimerScheduled (event history.Event , a * history.TimerScheduledAttributes ) error {
245
- e .workflowState .removeCommandByEventID (event .EventID )
245
+ e .workflowState .removeCommandByEventID (event .ScheduleEventID )
246
246
247
247
return nil
248
248
}
249
249
250
250
func (e * executor ) handleTimerFired (event history.Event , a * history.TimerFiredAttributes ) error {
251
- f , ok := e .workflowState .pendingFutures [event .EventID ]
251
+ f , ok := e .workflowState .pendingFutures [event .ScheduleEventID ]
252
252
if ! ok {
253
253
// Timer already canceled ignore
254
254
return nil
255
255
}
256
256
257
- e .workflowState .removeCommandByEventID (event .EventID )
257
+ e .workflowState .removeCommandByEventID (event .ScheduleEventID )
258
258
259
259
f .Set (nil , nil )
260
260
261
261
return e .workflow .Continue (e .workflowCtx )
262
262
}
263
263
264
264
func (e * executor ) handleSubWorkflowScheduled (event history.Event , a * history.SubWorkflowScheduledAttributes ) error {
265
- c := e .workflowState .removeCommandByEventID (event .EventID )
265
+ c := e .workflowState .removeCommandByEventID (event .ScheduleEventID )
266
266
if c != nil {
267
267
ca := c .Attr .(* command.ScheduleSubWorkflowCommandAttr )
268
268
if a .Name != ca .Name {
@@ -274,25 +274,25 @@ func (e *executor) handleSubWorkflowScheduled(event history.Event, a *history.Su
274
274
}
275
275
276
276
func (e * executor ) handleSubWorkflowFailed (event history.Event , a * history.SubWorkflowFailedAttributes ) error {
277
- f , ok := e .workflowState .pendingFutures [event .EventID ]
277
+ f , ok := e .workflowState .pendingFutures [event .ScheduleEventID ]
278
278
if ! ok {
279
279
return errors .New ("no pending future found for sub workflow failed event" )
280
280
}
281
281
282
- e .workflowState .removeCommandByEventID (event .EventID )
282
+ e .workflowState .removeCommandByEventID (event .ScheduleEventID )
283
283
284
284
f .Set (nil , errors .New (a .Error ))
285
285
286
286
return e .workflow .Continue (e .workflowCtx )
287
287
}
288
288
289
289
func (e * executor ) handleSubWorkflowCompleted (event history.Event , a * history.SubWorkflowCompletedAttributes ) error {
290
- f , ok := e .workflowState .pendingFutures [event .EventID ]
290
+ f , ok := e .workflowState .pendingFutures [event .ScheduleEventID ]
291
291
if ! ok {
292
292
return errors .New ("no pending future found for sub workflow completed event" )
293
293
}
294
294
295
- e .workflowState .removeCommandByEventID (event .EventID )
295
+ e .workflowState .removeCommandByEventID (event .ScheduleEventID )
296
296
297
297
f .Set (a .Result , nil )
298
298
@@ -304,13 +304,13 @@ func (e *executor) handleSignalReceived(event history.Event, a *history.SignalRe
304
304
sc := e .workflowState .getSignalChannel (a .Name )
305
305
sc .SendNonblocking (e .workflowCtx , a .Arg )
306
306
307
- e .workflowState .removeCommandByEventID (event .EventID )
307
+ e .workflowState .removeCommandByEventID (event .ScheduleEventID )
308
308
309
309
return e .workflow .Continue (e .workflowCtx )
310
310
}
311
311
312
312
func (e * executor ) handleSideEffectResult (event history.Event , a * history.SideEffectResultAttributes ) error {
313
- f , ok := e .workflowState .pendingFutures [event .EventID ]
313
+ f , ok := e .workflowState .pendingFutures [event .ScheduleEventID ]
314
314
if ! ok {
315
315
return errors .New ("no pending future found for side effect result event" )
316
316
}
@@ -321,8 +321,8 @@ func (e *executor) handleSideEffectResult(event history.Event, a *history.SideEf
321
321
}
322
322
323
323
func (e * executor ) workflowCompleted (result payload.Payload , err error ) error {
324
- eventId := e .workflowState .eventID
325
- e .workflowState .eventID ++
324
+ eventId := e .workflowState .scheduleEventID
325
+ e .workflowState .scheduleEventID ++
326
326
327
327
cmd := command .NewCompleteWorkflowCommand (eventId , result , err )
328
328
e .workflowState .addCommand (& cmd )
@@ -349,11 +349,11 @@ func (e *executor) processCommands(ctx context.Context, t *task.Workflow) ([]his
349
349
newEvents = append (newEvents , history .NewHistoryEvent (
350
350
e .clock .Now (),
351
351
history .EventType_ActivityScheduled ,
352
- c .ID ,
353
352
& history.ActivityScheduledAttributes {
354
353
Name : a .Name ,
355
354
Inputs : a .Inputs ,
356
355
},
356
+ history .ScheduleEventID (c .ID ),
357
357
))
358
358
359
359
case command .CommandType_ScheduleSubWorkflow :
@@ -364,12 +364,12 @@ func (e *executor) processCommands(ctx context.Context, t *task.Workflow) ([]his
364
364
newEvents = append (newEvents , history .NewHistoryEvent (
365
365
e .clock .Now (),
366
366
history .EventType_SubWorkflowScheduled ,
367
- c .ID ,
368
367
& history.SubWorkflowScheduledAttributes {
369
368
InstanceID : subWorkflowInstance .GetInstanceID (),
370
369
Name : a .Name ,
371
370
Inputs : a .Inputs ,
372
371
},
372
+ history .ScheduleEventID (c .ID ),
373
373
))
374
374
375
375
// Send message to new workflow instance
@@ -378,11 +378,11 @@ func (e *executor) processCommands(ctx context.Context, t *task.Workflow) ([]his
378
378
HistoryEvent : history .NewHistoryEvent (
379
379
e .clock .Now (),
380
380
history .EventType_WorkflowExecutionStarted ,
381
- c .ID ,
382
381
& history.ExecutionStartedAttributes {
383
382
Name : a .Name ,
384
383
Inputs : a .Inputs ,
385
384
},
385
+ history .ScheduleEventID (c .ID ),
386
386
),
387
387
})
388
388
@@ -391,10 +391,10 @@ func (e *executor) processCommands(ctx context.Context, t *task.Workflow) ([]his
391
391
newEvents = append (newEvents , history .NewHistoryEvent (
392
392
e .clock .Now (),
393
393
history .EventType_SideEffectResult ,
394
- c .ID ,
395
394
& history.SideEffectResultAttributes {
396
395
Result : a .Result ,
397
396
},
397
+ history .ScheduleEventID (c .ID ),
398
398
))
399
399
400
400
case command .CommandType_ScheduleTimer :
@@ -403,23 +403,23 @@ func (e *executor) processCommands(ctx context.Context, t *task.Workflow) ([]his
403
403
newEvents = append (newEvents , history .NewHistoryEvent (
404
404
e .clock .Now (),
405
405
history .EventType_TimerScheduled ,
406
- c .ID ,
407
406
& history.TimerScheduledAttributes {
408
407
At : a .At ,
409
408
},
409
+ history .ScheduleEventID (c .ID ),
410
410
))
411
411
412
412
// Create timer_fired event which will become visible in the future
413
413
workflowEvents = append (workflowEvents , core.WorkflowEvent {
414
414
WorkflowInstance : instance ,
415
- HistoryEvent : history .NewFutureHistoryEvent (
415
+ HistoryEvent : history .NewHistoryEvent (
416
416
e .clock .Now (),
417
417
history .EventType_TimerFired ,
418
- c .ID ,
419
418
& history.TimerFiredAttributes {
420
419
At : a .At ,
421
420
},
422
- a .At ,
421
+ history .ScheduleEventID (c .ID ),
422
+ history .VisibleAt (a .At ),
423
423
)},
424
424
)
425
425
@@ -429,11 +429,11 @@ func (e *executor) processCommands(ctx context.Context, t *task.Workflow) ([]his
429
429
newEvents = append (newEvents , history .NewHistoryEvent (
430
430
e .clock .Now (),
431
431
history .EventType_WorkflowExecutionFinished ,
432
- c .ID ,
433
432
& history.ExecutionCompletedAttributes {
434
433
Result : a .Result ,
435
434
Error : a .Error ,
436
435
},
436
+ history .ScheduleEventID (c .ID ),
437
437
))
438
438
439
439
if instance .SubWorkflow () {
@@ -445,19 +445,21 @@ func (e *executor) processCommands(ctx context.Context, t *task.Workflow) ([]his
445
445
historyEvent = history .NewHistoryEvent (
446
446
e .clock .Now (),
447
447
history .EventType_SubWorkflowFailed ,
448
- instance .ParentEventID (), // Ensure the message gets sent back to the parent workflow with the right eventID
449
448
& history.SubWorkflowFailedAttributes {
450
449
Error : a .Error ,
451
450
},
451
+ // Ensure the message gets sent back to the parent workflow with the right eventID
452
+ history .ScheduleEventID (instance .ParentEventID ()),
452
453
)
453
454
} else {
454
455
historyEvent = history .NewHistoryEvent (
455
456
e .clock .Now (),
456
457
history .EventType_SubWorkflowCompleted ,
457
- instance .ParentEventID (), // Ensure the message gets sent back to the parent workflow with the right eventID
458
458
& history.SubWorkflowCompletedAttributes {
459
459
Result : a .Result ,
460
460
},
461
+ // Ensure the message gets sent back to the parent workflow with the right eventID
462
+ history .ScheduleEventID (instance .ParentEventID ()),
461
463
)
462
464
}
463
465
0 commit comments