@@ -218,6 +218,11 @@ func (e *executor) executeNewEvents(newEvents []history.Event) ([]history.Event,
218
218
}
219
219
220
220
if e .workflow .Completed () {
221
+ // TODO: Is this too early? We haven't committed some of the commands
222
+ if e .workflowState .HasPendingFutures () {
223
+ panic ("Workflow completed, but there are still pending futures" )
224
+ }
225
+
221
226
e .workflowCompleted (e .workflow .Result (), e .workflow .Error ())
222
227
}
223
228
@@ -356,6 +361,8 @@ func (e *executor) handleActivityCompleted(event history.Event, a *history.Activ
356
361
return fmt .Errorf ("setting activity completed result: %w" , err )
357
362
}
358
363
364
+ e .workflowState .RemoveFuture (event .ScheduleEventID )
365
+
359
366
c := e .workflowState .CommandByScheduleEventID (event .ScheduleEventID )
360
367
if c == nil {
361
368
return fmt .Errorf ("previous workflow execution scheduled an activity which could not be found" )
@@ -381,6 +388,8 @@ func (e *executor) handleActivityFailed(event history.Event, a *history.Activity
381
388
return fmt .Errorf ("setting activity failed result: %w" , err )
382
389
}
383
390
391
+ e .workflowState .RemoveFuture (event .ScheduleEventID )
392
+
384
393
c := e .workflowState .CommandByScheduleEventID (event .ScheduleEventID )
385
394
if c == nil {
386
395
return fmt .Errorf ("previous workflow execution scheduled an activity which could not be found" )
@@ -422,6 +431,8 @@ func (e *executor) handleTimerFired(event history.Event, a *history.TimerFiredAt
422
431
return fmt .Errorf ("setting timer fired result: %w" , err )
423
432
}
424
433
434
+ e .workflowState .RemoveFuture (event .ScheduleEventID )
435
+
425
436
c := e .workflowState .CommandByScheduleEventID (event .ScheduleEventID )
426
437
if c == nil {
427
438
return fmt .Errorf ("no command found for timer fired event" )
@@ -460,6 +471,8 @@ func (e *executor) handleTimerCanceled(event history.Event, a *history.TimerCanc
460
471
return fmt .Errorf ("setting timer canceled result: %w" , err )
461
472
}
462
473
474
+ e .workflowState .RemoveFuture (event .ScheduleEventID )
475
+
463
476
return e .workflow .Continue ()
464
477
}
465
478
@@ -513,6 +526,8 @@ func (e *executor) handleSubWorkflowFailed(event history.Event, a *history.SubWo
513
526
return fmt .Errorf ("setting sub workflow failed result: %w" , err )
514
527
}
515
528
529
+ e .workflowState .RemoveFuture (event .ScheduleEventID )
530
+
516
531
c := e .workflowState .CommandByScheduleEventID (event .ScheduleEventID )
517
532
if c == nil {
518
533
// TODO: Adjust
@@ -539,6 +554,8 @@ func (e *executor) handleSubWorkflowCompleted(event history.Event, a *history.Su
539
554
return fmt .Errorf ("setting sub workflow completed result: %w" , err )
540
555
}
541
556
557
+ e .workflowState .RemoveFuture (event .ScheduleEventID )
558
+
542
559
c := e .workflowState .CommandByScheduleEventID (event .ScheduleEventID )
543
560
if c == nil {
544
561
// TODO: Adjust
@@ -600,6 +617,8 @@ func (e *executor) handleSideEffectResult(event history.Event, a *history.SideEf
600
617
return fmt .Errorf ("setting side effect result result: %w" , err )
601
618
}
602
619
620
+ e .workflowState .RemoveFuture (event .ScheduleEventID )
621
+
603
622
return e .workflow .Continue ()
604
623
}
605
624
0 commit comments