@@ -5,18 +5,19 @@ import (
5
5
"database/sql"
6
6
"strings"
7
7
8
+ "github.com/cschleiden/go-workflows/internal/core"
8
9
"github.com/cschleiden/go-workflows/internal/history"
9
10
)
10
11
11
- func insertPendingEvents (ctx context.Context , tx * sql.Tx , instanceID string , newEvents []* history.Event ) error {
12
- return insertEvents (ctx , tx , "pending_events" , instanceID , newEvents )
12
+ func insertPendingEvents (ctx context.Context , tx * sql.Tx , instance * core. WorkflowInstance , newEvents []* history.Event ) error {
13
+ return insertEvents (ctx , tx , "pending_events" , instance , newEvents )
13
14
}
14
15
15
- func insertHistoryEvents (ctx context.Context , tx * sql.Tx , instanceID string , historyEvents []* history.Event ) error {
16
- return insertEvents (ctx , tx , "history" , instanceID , historyEvents )
16
+ func insertHistoryEvents (ctx context.Context , tx * sql.Tx , instance * core. WorkflowInstance , historyEvents []* history.Event ) error {
17
+ return insertEvents (ctx , tx , "history" , instance , historyEvents )
17
18
}
18
19
19
- func insertEvents (ctx context.Context , tx * sql.Tx , tableName string , instanceID string , events []* history.Event ) error {
20
+ func insertEvents (ctx context.Context , tx * sql.Tx , tableName string , instance * core. WorkflowInstance , events []* history.Event ) error {
20
21
const batchSize = 20
21
22
for batchStart := 0 ; batchStart < len (events ); batchStart += batchSize {
22
23
batchEnd := batchStart + batchSize
@@ -25,8 +26,9 @@ func insertEvents(ctx context.Context, tx *sql.Tx, tableName string, instanceID
25
26
}
26
27
batchEvents := events [batchStart :batchEnd ]
27
28
28
- query := "INSERT INTO `" + tableName + "` (event_id, sequence_id, instance_id, event_type, timestamp, schedule_event_id, attributes, visible_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)" +
29
- strings .Repeat (", (?, ?, ?, ?, ?, ?, ?, ?)" , len (batchEvents )- 1 )
29
+ query := "INSERT INTO `" + tableName +
30
+ "` (event_id, sequence_id, instance_id, execution_id, event_type, timestamp, schedule_event_id, attributes, visible_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)" +
31
+ strings .Repeat (", (?, ?, ?, ?, ?, ?, ?, ?, ?)" , len (batchEvents )- 1 )
30
32
31
33
args := make ([]interface {}, 0 , len (batchEvents )* 7 )
32
34
@@ -36,7 +38,9 @@ func insertEvents(ctx context.Context, tx *sql.Tx, tableName string, instanceID
36
38
return err
37
39
}
38
40
39
- args = append (args , newEvent .ID , newEvent .SequenceID , instanceID , newEvent .Type , newEvent .Timestamp , newEvent .ScheduleEventID , a , newEvent .VisibleAt )
41
+ args = append (
42
+ args ,
43
+ newEvent .ID , newEvent .SequenceID , instance .InstanceID , instance .ExecutionID , newEvent .Type , newEvent .Timestamp , newEvent .ScheduleEventID , a , newEvent .VisibleAt )
40
44
}
41
45
42
46
_ , err := tx .ExecContext (
@@ -52,11 +56,12 @@ func insertEvents(ctx context.Context, tx *sql.Tx, tableName string, instanceID
52
56
return nil
53
57
}
54
58
55
- func removeFutureEvent (ctx context.Context , tx * sql.Tx , instanceID string , scheduleEventID int64 ) error {
59
+ func removeFutureEvent (ctx context.Context , tx * sql.Tx , instance * core. WorkflowInstance , scheduleEventID int64 ) error {
56
60
_ , err := tx .ExecContext (
57
61
ctx ,
58
- "DELETE FROM `pending_events` WHERE instance_id = ? AND schedule_event_id = ? AND visible_at IS NOT NULL" ,
59
- instanceID ,
62
+ "DELETE FROM `pending_events` WHERE instance_id = ? AND execution_id = ? AND schedule_event_id = ? AND visible_at IS NOT NULL" ,
63
+ instance .InstanceID ,
64
+ instance .ExecutionID ,
60
65
scheduleEventID ,
61
66
)
62
67
0 commit comments