@@ -269,7 +269,7 @@ func (e *executor) handleActivityScheduled(event history.Event, a *history.Activ
269
269
}
270
270
271
271
if c .Type != command .CommandType_ScheduleActivity {
272
- return fmt .Errorf ("previous workflow execution scheduled an activity, this time : %v" , c .Type )
272
+ return fmt .Errorf ("previous workflow execution scheduled an activity, not : %v" , c .Type )
273
273
}
274
274
275
275
// Ensure the same activity was scheduled again
@@ -287,7 +287,6 @@ func (e *executor) handleActivityCompleted(event history.Event, a *history.Activ
287
287
return fmt .Errorf ("could not find pending future for activity completion" )
288
288
}
289
289
290
- e .workflowState .RemoveCommandByEventID (event .ScheduleEventID )
291
290
err := f (a .Result , nil )
292
291
if err != nil {
293
292
return fmt .Errorf ("setting result: %w" , err )
@@ -302,8 +301,6 @@ func (e *executor) handleActivityFailed(event history.Event, a *history.Activity
302
301
return errors .New ("no pending future for activity failed event" )
303
302
}
304
303
305
- e .workflowState .RemoveCommandByEventID (event .ScheduleEventID )
306
-
307
304
if err := f (nil , errors .New (a .Reason )); err != nil {
308
305
return fmt .Errorf ("setting result: %w" , err )
309
306
}
@@ -312,7 +309,14 @@ func (e *executor) handleActivityFailed(event history.Event, a *history.Activity
312
309
}
313
310
314
311
func (e * executor ) handleTimerScheduled (event history.Event , a * history.TimerScheduledAttributes ) error {
315
- e .workflowState .RemoveCommandByEventID (event .ScheduleEventID )
312
+ c := e .workflowState .RemoveCommandByEventID (event .ScheduleEventID )
313
+ if c == nil {
314
+ return fmt .Errorf ("previous workflow execution scheduled a timer" )
315
+ }
316
+
317
+ if c .Type != command .CommandType_ScheduleTimer {
318
+ return fmt .Errorf ("previous workflow execution scheduled a timer, not: %v" , c .Type )
319
+ }
316
320
317
321
return nil
318
322
}
@@ -324,15 +328,6 @@ func (e *executor) handleTimerFired(event history.Event, a *history.TimerFiredAt
324
328
return nil
325
329
}
326
330
327
- c := e .workflowState .RemoveCommandByEventID (event .ScheduleEventID )
328
- if c == nil {
329
- return fmt .Errorf ("previous workflow execution scheduled a timer" )
330
- }
331
-
332
- if c .Type != command .CommandType_ScheduleTimer {
333
- return fmt .Errorf ("previous workflow execution scheduled a timer, this time: %v" , c .Type )
334
- }
335
-
336
331
if err := f (nil , nil ); err != nil {
337
332
return fmt .Errorf ("setting result: %w" , err )
338
333
}
@@ -347,8 +342,6 @@ func (e *executor) handleTimerCanceled(event history.Event, a *history.TimerCanc
347
342
return nil
348
343
}
349
344
350
- e .workflowState .RemoveCommandByEventID (event .ScheduleEventID )
351
-
352
345
if err := f (nil , nil ); err != nil {
353
346
return fmt .Errorf ("setting result: %w" , err )
354
347
}
@@ -363,7 +356,7 @@ func (e *executor) handleSubWorkflowScheduled(event history.Event, a *history.Su
363
356
}
364
357
365
358
if c .Type != command .CommandType_ScheduleSubWorkflow {
366
- return fmt .Errorf ("previous workflow execution scheduled a sub workflow, this time : %v" , c .Type )
359
+ return fmt .Errorf ("previous workflow execution scheduled a sub workflow, not : %v" , c .Type )
367
360
}
368
361
369
362
ca := c .Attr .(* command.ScheduleSubWorkflowCommandAttr )
@@ -386,7 +379,7 @@ func (e *executor) handleSubWorkflowCancellationRequest(event history.Event, a *
386
379
}
387
380
388
381
if c .Type != command .CommandType_CancelSubWorkflow {
389
- return fmt .Errorf ("previous workflow execution cancelled a sub-workflow execution, this time : %v" , c .Type )
382
+ return fmt .Errorf ("previous workflow execution cancelled a sub-workflow execution, not : %v" , c .Type )
390
383
}
391
384
392
385
return e .workflow .Continue (e .workflowCtx )
@@ -398,8 +391,6 @@ func (e *executor) handleSubWorkflowFailed(event history.Event, a *history.SubWo
398
391
return errors .New ("no pending future found for sub workflow failed event" )
399
392
}
400
393
401
- e .workflowState .RemoveCommandByEventID (event .ScheduleEventID )
402
-
403
394
if err := f (nil , errors .New (a .Error )); err != nil {
404
395
return fmt .Errorf ("setting result: %w" , err )
405
396
}
@@ -413,8 +404,6 @@ func (e *executor) handleSubWorkflowCompleted(event history.Event, a *history.Su
413
404
return errors .New ("no pending future found for sub workflow completed event" )
414
405
}
415
406
416
- e .workflowState .RemoveCommandByEventID (event .ScheduleEventID )
417
-
418
407
if err := f (a .Result , nil ); err != nil {
419
408
return fmt .Errorf ("setting result: %w" , err )
420
409
}
@@ -426,8 +415,6 @@ func (e *executor) handleSignalReceived(event history.Event, a *history.SignalRe
426
415
// Send signal to workflow channel
427
416
workflowstate .ReceiveSignal (e .workflowCtx , e .workflowState , a .Name , a .Arg )
428
417
429
- e .workflowState .RemoveCommandByEventID (event .ScheduleEventID )
430
-
431
418
return e .workflow .Continue (e .workflowCtx )
432
419
}
433
420
0 commit comments