77 Star 124 Fork 105

openEuler/PilotGo
关闭

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
scripts.go 1.36 KB
一键复制 编辑 原始数据 按行查看 历史
zhanghan 提交于 2025-09-16 20:14 +08:00 . Add script execution timeout control
package client
import (
"encoding/json"
"fmt"
"gitee.com/openeuler/PilotGo/sdk/common"
"gitee.com/openeuler/PilotGo/sdk/plugin/jwt"
"gitee.com/openeuler/PilotGo/sdk/utils/httputils"
)
type ScriptsRun struct {
Batch *common.Batch `json:"batch"`
ScriptType string `json:"script_type"`
ScriptContent string `json:"script_content"`
Params string `json:"params"`
TimeOutSec int `json:"timeoutSec"`
}
func (c *Client) AgentRunScripts(batch *common.Batch, scriptType string, script string, params string, timeoutSec int) ([]*common.CmdResult, error) {
serverInfo, err := c.Registry.Get("pilotgo-server")
if err != nil {
return nil, err
}
url := fmt.Sprintf("http://%s:%s/api/v1/pluginapi/runScripts", serverInfo.Address, serverInfo.Port)
scriptRun := &ScriptsRun{
Batch: batch,
ScriptType: scriptType,
ScriptContent: script,
Params: params,
TimeOutSec: timeoutSec,
}
r, err := httputils.Post(url, &httputils.Params{
Body: scriptRun,
Cookie: map[string]string{
jwt.TokenCookie: c.token,
},
})
if err != nil {
return nil, err
}
res := &struct {
Code int `json:"code"`
Message string `json:"msg"`
Data []*common.CmdResult `json:"data"`
}{}
if err := json.Unmarshal(r.Body, res); err != nil {
return nil, err
}
return res.Data, nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/openeuler/PilotGo.git
git@gitee.com:openeuler/PilotGo.git
openeuler
PilotGo
PilotGo
a82bc8e8fc49

搜索帮助