@@ -234,8 +234,9 @@ func (b *mysqlBackend) GetWorkflowInstanceHistory(ctx context.Context, instance
234
234
func (b * mysqlBackend ) GetWorkflowInstanceState (ctx context.Context , instance * workflow.Instance ) (core.WorkflowInstanceState , error ) {
235
235
row := b .db .QueryRowContext (
236
236
ctx ,
237
- "SELECT completed_at FROM instances WHERE instance_id = ?" ,
237
+ "SELECT completed_at FROM instances WHERE instance_id = ? AND execution_id = ? " ,
238
238
instance .InstanceID ,
239
+ instance .ExecutionID ,
239
240
)
240
241
241
242
var completedAt sql.NullTime
@@ -270,8 +271,9 @@ func createInstance(ctx context.Context, tx *sql.Tx, wfi *workflow.Instance, met
270
271
271
272
res , err := tx .ExecContext (
272
273
ctx ,
273
- "INSERT IGNORE INTO `instances` (instance_id, parent_instance_id, parent_schedule_event_id, metadata) VALUES (?, ?, ?, ?)" ,
274
+ "INSERT IGNORE INTO `instances` (instance_id, execution_id, parent_instance_id, parent_schedule_event_id, metadata) VALUES (?, ?, ?, ?, ?)" ,
274
275
wfi .InstanceID ,
276
+ wfi .ExecutionID ,
275
277
parentInstanceID ,
276
278
parentEventID ,
277
279
string (metadataJson ),
@@ -331,7 +333,7 @@ func (b *mysqlBackend) GetWorkflowTask(ctx context.Context) (*task.Workflow, err
331
333
now := time .Now ()
332
334
row := tx .QueryRowContext (
333
335
ctx ,
334
- `SELECT i.id, i.instance_id, i.parent_instance_id, i.parent_schedule_event_id, i.metadata, i.sticky_until
336
+ `SELECT i.id, i.instance_id, i.execution_id, i. parent_instance_id, i.parent_schedule_event_id, i.metadata, i.sticky_until
335
337
FROM instances i
336
338
INNER JOIN pending_events pe ON i.instance_id = pe.instance_id
337
339
WHERE
@@ -348,12 +350,12 @@ func (b *mysqlBackend) GetWorkflowTask(ctx context.Context) (*task.Workflow, err
348
350
)
349
351
350
352
var id int
351
- var instanceID string
353
+ var instanceID , executionID string
352
354
var parentInstanceID * string
353
355
var parentEventID * int64
354
356
var metadataJson sql.NullString
355
357
var stickyUntil * time.Time
356
- if err := row .Scan (& id , & instanceID , & parentInstanceID , & parentEventID , & metadataJson , & stickyUntil ); err != nil {
358
+ if err := row .Scan (& id , & instanceID , & executionID , & parentInstanceID , & parentEventID , & metadataJson , & stickyUntil ); err != nil {
357
359
if err == sql .ErrNoRows {
358
360
return nil , nil
359
361
}
@@ -383,9 +385,9 @@ func (b *mysqlBackend) GetWorkflowTask(ctx context.Context) (*task.Workflow, err
383
385
384
386
var wfi * workflow.Instance
385
387
if parentInstanceID != nil {
386
- wfi = core .NewSubWorkflowInstance (instanceID , * parentInstanceID , * parentEventID )
388
+ wfi = core .NewSubWorkflowInstance (instanceID , executionID , * parentInstanceID , * parentEventID )
387
389
} else {
388
- wfi = core .NewWorkflowInstance (instanceID )
390
+ wfi = core .NewWorkflowInstance (instanceID , executionID )
389
391
}
390
392
391
393
var metadata * core.WorkflowMetadata
@@ -495,10 +497,11 @@ func (b *mysqlBackend) CompleteWorkflowTask(
495
497
496
498
res , err := tx .ExecContext (
497
499
ctx ,
498
- `UPDATE instances SET locked_until = NULL, sticky_until = ?, completed_at = ? WHERE instance_id = ? AND worker = ?` ,
500
+ `UPDATE instances SET locked_until = NULL, sticky_until = ?, completed_at = ? WHERE instance_id = ? AND execution_id = ? AND worker = ?` ,
499
501
time .Now ().Add (b .options .StickyTimeout ),
500
502
completedAt ,
501
503
instance .InstanceID ,
504
+ instance .ExecutionID ,
502
505
b .workerName ,
503
506
)
504
507
if err != nil {
@@ -598,9 +601,10 @@ func (b *mysqlBackend) ExtendWorkflowTask(ctx context.Context, taskID string, in
598
601
until := time .Now ().Add (b .options .WorkflowLockTimeout )
599
602
res , err := tx .ExecContext (
600
603
ctx ,
601
- `UPDATE instances SET locked_until = ? WHERE instance_id = ? AND worker = ?` ,
604
+ `UPDATE instances SET locked_until = ? WHERE instance_id = ? AND execution_id = ? AND worker = ?` ,
602
605
until ,
603
606
instance .InstanceID ,
607
+ instance .ExecutionID ,
604
608
b .workerName ,
605
609
)
606
610
if err != nil {
@@ -630,7 +634,7 @@ func (b *mysqlBackend) GetActivityTask(ctx context.Context) (*task.Activity, err
630
634
now := time .Now ()
631
635
res := tx .QueryRowContext (
632
636
ctx ,
633
- `SELECT activities.id, activity_id, activities.instance_id,
637
+ `SELECT activities.id, activity_id, activities.instance_id, activities.execution_id,
634
638
event_type, timestamp, schedule_event_id, attributes, visible_at
635
639
FROM activities
636
640
WHERE activities.locked_until IS NULL OR activities.locked_until < ?
@@ -640,12 +644,12 @@ func (b *mysqlBackend) GetActivityTask(ctx context.Context) (*task.Activity, err
640
644
)
641
645
642
646
var id int64
643
- var instanceID string
647
+ var instanceID , executionID string
644
648
var attributes []byte
645
649
event := & history.Event {}
646
650
647
651
if err := res .Scan (
648
- & id , & event .ID , & instanceID , & event .Type ,
652
+ & id , & event .ID , & instanceID , & executionID , & event .Type ,
649
653
& event .Timestamp , & event .ScheduleEventID , & attributes , & event .VisibleAt ); err != nil {
650
654
if err == sql .ErrNoRows {
651
655
return nil , nil
@@ -673,7 +677,7 @@ func (b *mysqlBackend) GetActivityTask(ctx context.Context) (*task.Activity, err
673
677
674
678
t := & task.Activity {
675
679
ID : event .ID ,
676
- WorkflowInstance : core .NewWorkflowInstance (instanceID ),
680
+ WorkflowInstance : core .NewWorkflowInstance (instanceID , executionID ),
677
681
Event : event ,
678
682
}
679
683
@@ -697,9 +701,10 @@ func (b *mysqlBackend) CompleteActivityTask(ctx context.Context, instance *workf
697
701
// Remove activity
698
702
if res , err := tx .ExecContext (
699
703
ctx ,
700
- `DELETE FROM activities WHERE activity_id = ? AND instance_id = ? AND worker = ?` ,
704
+ `DELETE FROM activities WHERE activity_id = ? AND instance_id = ? AND execution_id = ? AND worker = ?` ,
701
705
id ,
702
706
instance .InstanceID ,
707
+ instance .ExecutionID ,
703
708
b .workerName ,
704
709
); err != nil {
705
710
return fmt .Errorf ("completing activity: %w" , err )
@@ -763,9 +768,10 @@ func scheduleActivity(ctx context.Context, tx *sql.Tx, instance *core.WorkflowIn
763
768
_ , err = tx .ExecContext (
764
769
ctx ,
765
770
`INSERT INTO activities
766
- (activity_id, instance_id, event_type, timestamp, schedule_event_id, attributes, visible_at) VALUES (?, ?, ?, ?, ?, ?, ?)` ,
771
+ (activity_id, instance_id, execution_id, event_type, timestamp, schedule_event_id, attributes, visible_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)` ,
767
772
event .ID ,
768
773
instance .InstanceID ,
774
+ instance .ExecutionID ,
769
775
event .Type ,
770
776
event .Timestamp ,
771
777
event .ScheduleEventID ,
0 commit comments