[优化] 设置状态监控

This commit is contained in:
PandaX-Go
2024-12-04 21:47:24 +08:00
parent 7c021f8be9
commit ffe6e859af
18 changed files with 314 additions and 410 deletions

View File

@@ -1,37 +1,30 @@
package rule_engine
import (
"context"
"errors"
"pandax/pkg/rule_engine/manifest"
"pandax/pkg/rule_engine/message"
"pandax/pkg/rule_engine/nodes"
"github.com/sirupsen/logrus"
)
var ruleChainDebugData = message.NewRuleChainDebugData(100)
type RuleChainInstance struct {
ruleID string
ruleId string
firstRuleNodeID string
nodes map[string]nodes.Node
}
func NewRuleChainInstance(ruleID string, data []byte) (*RuleChainInstance, error) {
instance := &RuleChainInstance{}
func NewRuleChainInstance(ruleId string, data []byte) (*RuleChainInstance, error) {
manifest, err := manifest.New(data)
if err != nil {
logrus.WithError(err).Errorf("invalid manifest file")
return nil, err
}
instance, err = newInstanceWithManifest(manifest)
withManifest, err := newInstanceWithManifest(manifest)
if err != nil {
return nil, err
}
instance.ruleID = ruleID
return instance, nil
withManifest.ruleId = ruleId
return withManifest, nil
}
func newInstanceWithManifest(m *manifest.Manifest) (*RuleChainInstance, error) {
@@ -45,29 +38,3 @@ func newInstanceWithManifest(m *manifest.Manifest) (*RuleChainInstance, error) {
}
return r, nil
}
func (c *RuleChainInstance) StartRuleChain(ctx context.Context, msg *message.Message) error {
debugChan := make(chan *message.DebugData, 100)
endDebugChan := make(chan struct{})
go func() {
for {
select {
case debugMsg := <-debugChan:
ruleChainDebugData.Add(c.ruleID, debugMsg.NodeId, *debugMsg)
case <-endDebugChan:
logrus.Debugf("规则链%s,执行结束", msg.Id)
return
}
}
}()
node, found := c.nodes[c.firstRuleNodeID]
if !found {
return errors.New("first rule node not found")
}
err := node.Handle(msg)
endDebugChan <- struct{}{}
return err
}