@@ -227,10 +227,17 @@ func (sb *sqliteBackend) RemoveWorkflowInstance(ctx context.Context, instance *c
227
227
}
228
228
defer tx .Rollback ()
229
229
230
+ if err := sb .removeWorkflowInstance (ctx , instance , tx ); err != nil {
231
+ return err
232
+ }
233
+
234
+ return tx .Commit ()
235
+ }
236
+
237
+ func (sb * sqliteBackend ) removeWorkflowInstance (ctx context.Context , instance * core.WorkflowInstance , tx * sql.Tx ) error {
230
238
instanceID := instance .InstanceID
231
239
executionID := instance .ExecutionID
232
240
233
- // Check status of the instance
234
241
row := tx .QueryRowContext (ctx , "SELECT state FROM `instances` WHERE id = ? AND execution_id = ? LIMIT 1" , instanceID , executionID )
235
242
var state core.WorkflowInstanceState
236
243
if err := row .Scan (& state ); err != nil {
@@ -243,7 +250,6 @@ func (sb *sqliteBackend) RemoveWorkflowInstance(ctx context.Context, instance *c
243
250
return backend .ErrInstanceNotFinished
244
251
}
245
252
246
- // Delete from instances and history tables
247
253
if _ , err := tx .ExecContext (ctx , "DELETE FROM `instances` WHERE id = ? AND execution_id = ?" , instanceID , executionID ); err != nil {
248
254
return err
249
255
}
@@ -256,7 +262,7 @@ func (sb *sqliteBackend) RemoveWorkflowInstance(ctx context.Context, instance *c
256
262
return err
257
263
}
258
264
259
- return tx . Commit ()
265
+ return nil
260
266
}
261
267
262
268
func (sb * sqliteBackend ) RemoveWorkflowInstances (ctx context.Context , options ... backend.RemovalOption ) error {
@@ -539,6 +545,7 @@ func (sb *sqliteBackend) GetWorkflowTask(ctx context.Context, queues []workflow.
539
545
return t , nil
540
546
}
541
547
548
+ // MARK: CompleteWorkflowTask
542
549
func (sb * sqliteBackend ) CompleteWorkflowTask (
543
550
ctx context.Context ,
544
551
task * backend.WorkflowTask ,
@@ -670,6 +677,12 @@ func (sb *sqliteBackend) CompleteWorkflowTask(
670
677
}
671
678
}
672
679
680
+ if sb .options .RemoveContinuedAsNewInstances && state == core .WorkflowInstanceStateContinuedAsNew {
681
+ if err := sb .removeWorkflowInstance (ctx , instance , tx ); err != nil {
682
+ return fmt .Errorf ("removing old instance: %w" , err )
683
+ }
684
+ }
685
+
673
686
return tx .Commit ()
674
687
}
675
688
0 commit comments