-
Notifications
You must be signed in to change notification settings - Fork 3
/
link.go
95 lines (80 loc) · 1.6 KB
/
link.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
package zenmodel
import (
"github.com/zenmodel/zenmodel/internal/utils"
"go.uber.org/zap/zapcore"
)
const (
EntryLinkFrom = "EXTERNAL_SIGNAL"
EndLinkTo = EndNeuronID
)
type Link struct {
// ID 不可编辑
id string
// state 不可编辑,
state LinkState
count struct {
// from 执行完整,开始尝试传递的次数
process int
// 传递成功的次数
succeed int
// 传递失败的次数。可能是超时、其他触发组触发当前的取消等原因
failed int
}
// from neuron ID
from string
// to neuron ID
to string
}
type LinkState string
const (
LinkStateInit LinkState = "Init"
LinkStateWait LinkState = "Wait"
LinkStateReady LinkState = "Ready"
)
func newLink(from, to *Neuron) *Link {
return &Link{
id: utils.GenUUID(),
state: LinkStateInit,
from: from.id,
to: to.id,
}
}
func newEntryLink(to *Neuron) *Link {
return &Link{
id: utils.GenUUID(),
state: LinkStateInit,
from: EntryLinkFrom,
to: to.id,
}
}
func (l *Link) Clone() *Link {
return l.deepCopy()
}
func (l *Link) deepCopy() *Link {
if l == nil {
return nil
}
cp := &Link{
id: l.id,
state: l.state,
from: l.from,
to: l.to,
}
cp.count.process = l.count.process
cp.count.succeed = l.count.succeed
cp.count.failed = l.count.failed
return cp
}
func (l *Link) IsEntryLink() bool {
if l.from == EntryLinkFrom {
return true
}
return false
}
func (l *Link) MarshalLogObject(enc zapcore.ObjectEncoder) error {
enc.AddString("id", l.id)
enc.AddString("state", string(l.state))
enc.AddString("src", l.from)
enc.AddString("dest", l.to)
return nil
}