Skip to content

Commit 6b87cbd

Browse files
committed
Fix side effect determinism check during replay
#116
1 parent 4164a90 commit 6b87cbd

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

internal/command/sideeffect.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,19 @@ type SideEffectCommand struct {
1414

1515
var _ Command = (*SideEffectCommand)(nil)
1616

17-
func NewSideEffectCommand(id int64, result payload.Payload) *SideEffectCommand {
17+
func NewSideEffectCommand(id int64) *SideEffectCommand {
1818
return &SideEffectCommand{
1919
command: command{
2020
state: CommandState_Pending,
2121
id: id,
2222
},
23-
result: result,
2423
}
2524
}
2625

26+
func (c *SideEffectCommand) SetResult(result payload.Payload) {
27+
c.result = result
28+
}
29+
2730
func (c *SideEffectCommand) Type() string {
2831
return "SideEffect"
2932
}

workflow/sideeffect.go

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,23 @@ func SideEffect[TResult any](ctx Context, f func(ctx Context) TResult) Future[TR
2222
wfState := workflowstate.WorkflowState(ctx)
2323
scheduleEventID := wfState.GetNextScheduleEventID()
2424

25-
if Replaying(ctx) {
26-
// There has to be a message in the history with the result, create a new future
27-
// and block on it
28-
wfState.TrackFuture(scheduleEventID, workflowstate.AsDecodingSettable(future))
29-
return future
30-
}
25+
wfState.TrackFuture(scheduleEventID, workflowstate.AsDecodingSettable(future))
3126

32-
// Execute side effect
33-
r := f(ctx)
27+
cmd := command.NewSideEffectCommand(scheduleEventID)
28+
wfState.AddCommand(cmd)
3429

35-
// Create command to add it to the history
36-
payload, err := converter.DefaultConverter.To(r)
37-
if err != nil {
38-
future.Set(*new(TResult), err)
39-
}
30+
if !Replaying(ctx) {
31+
// Execute side effect
32+
r := f(ctx)
4033

41-
cmd := command.NewSideEffectCommand(scheduleEventID, payload)
42-
wfState.AddCommand(cmd)
34+
payload, err := converter.DefaultConverter.To(r)
35+
if err != nil {
36+
future.Set(*new(TResult), err)
37+
}
4338

44-
future.Set(r, nil)
39+
cmd.SetResult(payload)
40+
future.Set(r, nil)
41+
}
4542

4643
return future
4744
}

0 commit comments

Comments
 (0)