feat: add pre and post command

This commit is contained in:
duorameng
2026-05-08 20:18:00 +08:00
parent 2f88fa0718
commit a3871e75b7
17 changed files with 255 additions and 67 deletions
+19 -2
View File
@@ -21,6 +21,8 @@ type Task interface {
GetID() string
GetName() string
GetCommand() string
GetPreCommand() string
GetPostCommand() string
GetTimeout() int
GetWorkDir() string
GetEnvs() string
@@ -40,8 +42,10 @@ type CronTask interface {
// Request 任务执行请求
type Request struct {
Command string
WorkDir string
Command string
PreCommand string
PostCommand string
WorkDir string
Envs []string
Timeout int // 任务超时时间(分钟)
Languages []map[string]string
@@ -121,6 +125,19 @@ func ExecuteWithHooks(ctx context.Context, req Request, stdout, stderr io.Writer
req.UseMise = false
}
// 组合指令(如果存在前置或后置指令)
if req.PreCommand != "" || req.PostCommand != "" {
finalCmd := ""
if req.PreCommand != "" {
finalCmd += req.PreCommand + "\n"
}
finalCmd += req.Command
if req.PostCommand != "" {
finalCmd += "\n" + req.PostCommand
}
req.Command = finalCmd
}
// 1. 执行前钩子
var logID string
if hooks != nil {