feat: udpate mise exec logs

This commit is contained in:
engigu
2026-02-13 21:16:51 +08:00
parent ef0d256c58
commit 2d90d0921a
19 changed files with 180 additions and 63 deletions
+15 -38
View File
@@ -76,6 +76,20 @@ func Execute(ctx context.Context, req Request, stdout, stderr io.Writer) (*Resul
func ExecuteWithHooks(ctx context.Context, req Request, stdout, stderr io.Writer, hooks Hooks) (*Result, error) {
start := time.Now()
// 2. 执行命令
timeout := req.Timeout
if timeout <= 0 {
timeout = 30
}
execCtx, cancel := context.WithTimeout(ctx, time.Duration(timeout)*time.Minute)
defer cancel()
// 如果指定使用 mise,则预先构建好带 mise 的命令,这样 PreExecute 记录的就是完整命令
if req.UseMise {
req.Command = utils.BuildMiseCommand(req.Command, req.Languages)
req.UseMise = false
}
// 1. 执行前钩子
var logID uint
if hooks != nil {
@@ -92,19 +106,7 @@ func ExecuteWithHooks(ctx context.Context, req Request, stdout, stderr io.Writer
logID = id
}
// 2. 执行命令
timeout := req.Timeout
if timeout <= 0 {
timeout = 30
}
execCtx, cancel := context.WithTimeout(ctx, time.Duration(timeout)*time.Minute)
defer cancel()
finalCommand := req.Command
if req.UseMise {
finalCommand = BuildLanguageCommand(req.Command, req.Languages)
}
shell, args := utils.GetShellCommand(finalCommand)
shell, args := utils.GetShellCommand(req.Command)
cmd := exec.CommandContext(execCtx, shell, args...)
// 设置工作目录
@@ -280,31 +282,6 @@ func ExecuteWithHooks(ctx context.Context, req Request, stdout, stderr io.Writer
return result, err
}
// BuildLanguageCommand 构建语言环境执行命令 (使用 mise)
func BuildLanguageCommand(command string, languages []map[string]string) string {
if len(languages) == 0 {
return command
}
var builder strings.Builder
builder.WriteString("mise exec")
for _, lang := range languages {
name := lang["name"]
version := lang["version"]
if name == "" {
continue
}
if version == "" {
version = "latest"
}
builder.WriteString(" " + name + "@" + version)
}
builder.WriteString(" -- " + command)
return builder.String()
}
// ParseEnvVars 解析环境变量字符串 "KEY1=VALUE1,KEY2=VALUE2"
func ParseEnvVars(envStr string) []string {
if envStr == "" {
+5 -3
View File
@@ -10,6 +10,7 @@ import (
"time"
"github.com/engigu/baihu-panel/internal/constant"
"github.com/engigu/baihu-panel/internal/utils"
)
// safeBuffer 一个线程安全的字节缓冲区,用于合并 stdout 和 stderr
@@ -313,11 +314,12 @@ func (s *Scheduler) executeTask(req *ExecutionRequest) (*ExecutionResult, error)
s.logger.Infof("[Scheduler] 执行任务 %s (名称: %s, 类型: %s)", req.TaskID, req.Name, req.Type)
finalCommand := req.Command
// 如果指定使用 mise,则预先构建好带 mise 的命令,这样 OnTaskExecuting 记录的就是完整命令
if req.UseMise {
finalCommand = BuildLanguageCommand(req.Command, req.Languages)
req.Command = utils.BuildMiseCommand(req.Command, req.Languages)
req.UseMise = false
}
s.logger.Infof("[Scheduler] 实际执行命令: %s", finalCommand)
s.logger.Infof("[Scheduler] 实际执行命令: %s", req.Command)
if s.config.Verbose {
workDir := req.WorkDir