feat: refact id column define
This commit is contained in:
@@ -59,13 +59,13 @@ type Result struct {
|
||||
// Hooks 执行钩子接口
|
||||
type Hooks interface {
|
||||
// PreExecute 执行前钩子,返回日志ID和错误
|
||||
PreExecute(ctx context.Context, req Request) (logID uint, err error)
|
||||
PreExecute(ctx context.Context, req Request) (logID string, err error)
|
||||
|
||||
// PostExecute 执行后钩子,处理日志压缩和记录更新
|
||||
PostExecute(ctx context.Context, logID uint, result *Result) error
|
||||
PostExecute(ctx context.Context, logID string, result *Result) error
|
||||
|
||||
// OnHeartbeat 执行中心跳钩子,用于更新实时状态
|
||||
OnHeartbeat(ctx context.Context, logID uint, duration int64) error
|
||||
OnHeartbeat(ctx context.Context, logID string, duration int64) error
|
||||
}
|
||||
|
||||
// Execute 执行命令(基础版本,不带钩子)
|
||||
@@ -85,7 +85,7 @@ func ExecuteWithHooks(ctx context.Context, req Request, stdout, stderr io.Writer
|
||||
}
|
||||
|
||||
// 仍然触发 PreExecute 以便流程完整
|
||||
var logID uint
|
||||
var logID string
|
||||
if hooks != nil {
|
||||
logID, _ = hooks.PreExecute(ctx, req)
|
||||
}
|
||||
@@ -118,7 +118,7 @@ func ExecuteWithHooks(ctx context.Context, req Request, stdout, stderr io.Writer
|
||||
}
|
||||
|
||||
// 1. 执行前钩子
|
||||
var logID uint
|
||||
var logID string
|
||||
if hooks != nil {
|
||||
id, err := hooks.PreExecute(ctx, req)
|
||||
if err != nil {
|
||||
@@ -171,7 +171,7 @@ func ExecuteWithHooks(ctx context.Context, req Request, stdout, stderr io.Writer
|
||||
)
|
||||
f, ptyErr := pty.Start(cmd)
|
||||
if ptyErr == nil {
|
||||
logger.Infof("[Executor] 任务 #%d 启动于 PTY 模式", logID)
|
||||
logger.Infof("[Executor] 任务 #%s 启动于 PTY 模式", logID)
|
||||
ptyFile = f
|
||||
started = true
|
||||
copyDone = make(chan struct{})
|
||||
@@ -182,7 +182,7 @@ func ExecuteWithHooks(ctx context.Context, req Request, stdout, stderr io.Writer
|
||||
f.Close()
|
||||
}()
|
||||
} else {
|
||||
logger.Errorf("[Executor] 任务 #%d PTY 启动失败: %v", logID, ptyErr)
|
||||
logger.Errorf("[Executor] 任务 #%s PTY 启动失败: %v", logID, ptyErr)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ func ExecuteWithHooks(ctx context.Context, req Request, stdout, stderr io.Writer
|
||||
if stdout != stderr && stdout != io.Discard {
|
||||
logger.Debugf("[Executor] 任务 #%d stdout (%p) 和 stderr (%p) 不同,回退到 Pipe 模式。", logID, stdout, stderr)
|
||||
}
|
||||
logger.Infof("[Executor] 任务 #%d 启动于 Pipe 模式", logID)
|
||||
logger.Infof("[Executor] 任务 #%s 启动于 Pipe 模式", logID)
|
||||
if stdout != nil && stdout == stderr {
|
||||
pr, pw, err := os.Pipe()
|
||||
if err == nil {
|
||||
|
||||
Reference in New Issue
Block a user