-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.go
152 lines (139 loc) · 4.01 KB
/
log.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package flowstate
import (
"fmt"
"log/slog"
"strconv"
)
func logExecute(stateCtx *StateCtx, l *slog.Logger) {
args := []any{
"sess", stateCtx.sessID,
"flow", stateCtx.Current.Transition.ToID,
"id", stateCtx.Current.ID,
"rev", stateCtx.Current.Rev,
}
currTs := stateCtx.Current.Transition
if currTs.Annotations[StateAnnotation] != `` {
args = append(args, "state", currTs.Annotations[StateAnnotation])
}
if currTs.Annotations[DelayDurationAnnotation] != `` {
args = append(args, "delayed", "true")
}
if currTs.Annotations[RecoveryAttemptAnnotation] != `` {
args = append(args, "recovered", currTs.Annotations[RecoveryAttemptAnnotation])
}
args = append(args, "labels", stateCtx.Current.Labels)
l.Info("engine: execute", args...)
}
func logDo(execSessID int64, cmd0 Command, l *slog.Logger) {
var args []any
if execSessID > 0 {
args = []any{"sess", strconv.FormatInt(execSessID, 10) + ":" + strconv.FormatInt(cmd0.SessID(), 10)}
} else {
args = []any{"sess", cmd0.SessID()}
}
switch cmd := cmd0.(type) {
case *CommitCommand:
args = append(args, "cmd", "commit", "len", len(cmd.Commands))
case *CommitStateCtxCommand:
args = append(args, "cmd", "commit_state_ctx", "id", cmd.StateCtx.Current.ID, "rev", cmd.StateCtx.Current.Rev)
case *TransitCommand:
args = append(args,
"cmd", "transit",
"id", cmd.StateCtx.Current.ID,
"rev", cmd.StateCtx.Current.Rev,
"to", cmd.FlowID,
"labels", cmd.StateCtx.Current.Labels,
)
case *PauseCommand:
args = append(args,
"cmd", "pause",
"id", cmd.StateCtx.Current.ID,
"rev", cmd.StateCtx.Current.Rev,
)
if cmd.FlowID != `` {
args = append(args, "to", cmd.FlowID)
}
args = append(args, "labels", cmd.StateCtx.Current.Labels)
case *ResumeCommand:
args = append(args,
"cmd", "resume",
"id", cmd.StateCtx.Current.ID,
"rev", cmd.StateCtx.Current.Rev,
"labels", cmd.StateCtx.Current.Labels,
)
case *EndCommand:
args = append(args,
"cmd", "end",
"id", cmd.StateCtx.Current.ID,
"rev", cmd.StateCtx.Current.Rev,
"labels", cmd.StateCtx.Current.Labels,
)
case *DelayCommand:
args = append(args,
"cmd", "delay",
"id", cmd.StateCtx.Current.ID,
"rev", cmd.StateCtx.Current.Rev,
"dur", cmd.Duration,
"labels", cmd.StateCtx.Current.Labels,
)
case *ExecuteCommand:
args = append(args,
"cmd", "execute",
"id", cmd.StateCtx.Current.ID,
"rev", cmd.StateCtx.Current.Rev,
"labels", cmd.StateCtx.Current.Labels,
)
case *NoopCommand:
args = append(args,
"cmd", "noop",
"id", cmd.StateCtx.Current.ID,
"rev", cmd.StateCtx.Current.Rev,
"labels", cmd.StateCtx.Current.Labels,
)
case *ReferenceDataCommand:
args = append(args,
"cmd", "reference_data",
"id", cmd.StateCtx.Current.ID,
"rev", cmd.StateCtx.Current.Rev,
"data_id", cmd.Data.ID,
"data_rev", cmd.Data.Rev,
"annot", cmd.Annotation,
)
case *DereferenceDataCommand:
args = append(args,
"cmd", "dereference_data",
"id", cmd.StateCtx.Current.ID,
"rev", cmd.StateCtx.Current.Rev,
"data_id", cmd.Data.ID,
"data_rev", cmd.Data.Rev,
"annot", cmd.Annotation,
)
case *StoreDataCommand:
args = append(args, "cmd", "store_data", "data_id", cmd.Data.ID, "data_rev", cmd.Data.Rev)
case *GetDataCommand:
args = append(args, "cmd", "get_data", "data_id", cmd.Data.ID, "data_rev", cmd.Data.Rev)
case *DeserializeCommand:
args = append(args, "cmd", "deserialize")
case *SerializeCommand:
args = append(args, "cmd", "serialize")
case *GetFlowCommand:
args = append(args, "cmd", "get_flow", "flow_id", cmd.StateCtx.Current.Transition.ToID)
case *WatchCommand:
args = append(args, "cmd", "watch")
if cmd.SinceLatest == true {
args = append(args, "since_latest", "true")
}
if cmd.SinceRev > 0 {
args = append(args, "since_rev", cmd.SinceRev)
}
if !cmd.SinceTime.IsZero() {
args = append(args, "since_time", cmd.SinceTime)
}
if len(cmd.Labels) > 0 {
args = append(args, "labels", cmd.Labels)
}
default:
args = append(args, "cmd", fmt.Sprintf("%T", cmd))
}
l.Info("engine: do", args...)
}