@@ -89,7 +89,9 @@ func (b *mysqlBackend) Logger() log.Logger {
89
89
}
90
90
91
91
func (b * mysqlBackend ) CancelWorkflowInstance (ctx context.Context , instance * workflow.Instance , event * history.Event ) error {
92
- tx , err := b .db .BeginTx (ctx , nil )
92
+ tx , err := b .db .BeginTx (ctx , & sql.TxOptions {
93
+ Isolation : sql .LevelReadCommitted ,
94
+ })
93
95
if err != nil {
94
96
return err
95
97
}
@@ -104,17 +106,17 @@ func (b *mysqlBackend) CancelWorkflowInstance(ctx context.Context, instance *wor
104
106
return backend .ErrInstanceNotFound
105
107
}
106
108
107
- if err := insertNewEvents (ctx , tx , instanceID , []history.Event {* event }); err != nil {
108
- return fmt .Errorf ("inserting cancellation event: %w" , err )
109
- }
110
-
111
109
// Recursively, find any sub-workflow instance to cancel
112
110
toCancel := []string {instance .InstanceID }
113
111
114
112
for len (toCancel ) > 0 {
115
113
toCancelID := toCancel [0 ]
116
114
toCancel = toCancel [1 :]
117
115
116
+ if err := insertNewEvents (ctx , tx , toCancelID , []history.Event {* event }); err != nil {
117
+ return fmt .Errorf ("inserting cancellation event: %w" , err )
118
+ }
119
+
118
120
rows , err := tx .QueryContext (ctx , "SELECT instance_id FROM `instances` WHERE parent_instance_id = ? AND completed_at IS NULL" , toCancelID )
119
121
defer rows .Close ()
120
122
if err != nil {
@@ -127,11 +129,6 @@ func (b *mysqlBackend) CancelWorkflowInstance(ctx context.Context, instance *wor
127
129
return fmt .Errorf ("geting workflow instance for canceling: %w" , err )
128
130
}
129
131
130
- // Cancel sub-workflow instance
131
- if err := insertNewEvents (ctx , tx , subWorkflowInstanceID , []history.Event {* event }); err != nil {
132
- return fmt .Errorf ("inserting cancellation event: %w" , err )
133
- }
134
-
135
132
toCancel = append (toCancel , subWorkflowInstanceID )
136
133
}
137
134
}
0 commit comments