Documentation
¶
Index ¶
Constants ¶
View Source
const FunctionNameProcess = "Process"
FunctionNameProcess is the name of the function to be called in the script
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PythonNode ¶
type PythonNode struct {
Config PythonNodeConfiguration
// contains filtered or unexported fields
}
PythonNode is an action component that executes Python scripts. It spawns a python3 subprocess for each message, passes input via stdin JSON, and reads the result from stdout JSON.
JSON rule chain DSL example:
{
"id": "s1",
"type": "x/python",
"name": "Python处理",
"configuration": {
"script": "import json\ndata = json.loads(msg) if isinstance(msg, str) else msg\ndata['processed'] = True\nreturn json.dumps(data), metadata, msgType",
"pythonPath": "python3",
"timeout": "5s",
"maxRunning": 10
}
}
func (*PythonNode) Destroy ¶
func (x *PythonNode) Destroy()
Destroy releases the resources of the component
func (*PythonNode) Init ¶
func (x *PythonNode) Init(ruleConfig types.Config, configuration types.Configuration) error
Init initializes the component
func (*PythonNode) New ¶
func (x *PythonNode) New() types.Node
New creates a new instance of PythonNode
func (*PythonNode) OnMsg ¶
func (x *PythonNode) OnMsg(ctx types.RuleContext, msg types.RuleMsg)
OnMsg handles the message by executing the Python script
type PythonNodeConfiguration ¶
type PythonNodeConfiguration struct {
Script string `json:"script" label:"Script" desc:"Python script content or .py file path" required:"true"`
PythonPath string `json:"pythonPath" label:"Python Path" desc:"Python interpreter path, uses system PATH by default"`
Timeout string `json:"timeout" label:"Timeout" desc:"Script execution timeout, e.g. 10s, 1m"`
MaxRunning int `json:"maxRunning" label:"Max Running" desc:"Max concurrent executions, default 1"`
}
PythonNodeConfiguration node configuration
Click to show internal directories.
Click to hide internal directories.