chore: udpate task execute log
This commit is contained in:
@@ -128,12 +128,12 @@ func (m *CronManager) AddTask(task CronTask) error {
|
|||||||
// 生成 0 到 randomRange 之间的随机秒数
|
// 生成 0 到 randomRange 之间的随机秒数
|
||||||
delaySeconds := rand.Intn(randomRange)
|
delaySeconds := rand.Intn(randomRange)
|
||||||
delay := time.Duration(delaySeconds) * time.Second
|
delay := time.Duration(delaySeconds) * time.Second
|
||||||
m.logger.Infof("[CronManager] 任务 #%s 将随机延迟 %v (范围: %ds) 后入队执行", taskID, delay, randomRange)
|
m.logger.Infof("[CronManager] 任务 %s (#%s) 将随机延迟 %v (范围: %ds) 后入队", name, taskID, delay, randomRange)
|
||||||
|
|
||||||
// 使用调度器的延时投递功能,不阻塞当前 Cron 协程
|
// 使用调度器的延时投递功能,不阻塞当前 Cron 协程
|
||||||
m.scheduler.EnqueueDelayed(delay, reqBuilder)
|
m.scheduler.EnqueueDelayed(delay, reqBuilder)
|
||||||
} else {
|
} else {
|
||||||
m.logger.Infof("[CronManager] 触发计划任务 #%s (%s)", taskID, name)
|
m.logger.Infof("[CronManager] 触发计划任务: %s (#%s)", name, taskID)
|
||||||
if m.scheduler != nil {
|
if m.scheduler != nil {
|
||||||
m.scheduler.EnqueueOrExecute(reqBuilder())
|
m.scheduler.EnqueueOrExecute(reqBuilder())
|
||||||
}
|
}
|
||||||
@@ -149,7 +149,7 @@ func (m *CronManager) AddTask(task CronTask) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
m.entryMap[taskID] = entryID
|
m.entryMap[taskID] = entryID
|
||||||
m.logger.Infof("[CronManager] 任务已添加调度 #%s %s (%s)", taskID, name, task.GetSchedule())
|
m.logger.Infof("[CronManager] 已添加调度: %s (#%s) [%s]", name, taskID, task.GetSchedule())
|
||||||
|
|
||||||
// 初始触发一次下次运行时间通知
|
// 初始触发一次下次运行时间通知
|
||||||
go func() {
|
go func() {
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ func ExecuteWithHooks(ctx context.Context, req Request, stdout, stderr io.Writer
|
|||||||
)
|
)
|
||||||
f, ptyErr := pty.Start(cmd)
|
f, ptyErr := pty.Start(cmd)
|
||||||
if ptyErr == nil {
|
if ptyErr == nil {
|
||||||
logger.Infof("[Executor] 任务 #%s 启动于 PTY 模式", logID)
|
logger.Infof("[Executor] #%s 启动于 PTY 模式", logID)
|
||||||
ptyFile = f
|
ptyFile = f
|
||||||
started = true
|
started = true
|
||||||
copyDone = make(chan struct{})
|
copyDone = make(chan struct{})
|
||||||
@@ -196,7 +196,7 @@ func ExecuteWithHooks(ctx context.Context, req Request, stdout, stderr io.Writer
|
|||||||
if stdout != stderr && stdout != io.Discard {
|
if stdout != stderr && stdout != io.Discard {
|
||||||
logger.Debugf("[Executor] 任务 #%d stdout (%p) 和 stderr (%p) 不同,回退到 Pipe 模式。", logID, stdout, stderr)
|
logger.Debugf("[Executor] 任务 #%d stdout (%p) 和 stderr (%p) 不同,回退到 Pipe 模式。", logID, stdout, stderr)
|
||||||
}
|
}
|
||||||
logger.Infof("[Executor] 任务 #%s 启动于 Pipe 模式", logID)
|
logger.Infof("[Executor] #%s 启动于 Pipe 模式", logID)
|
||||||
if stdout != nil && stdout == stderr {
|
if stdout != nil && stdout == stderr {
|
||||||
pr, pw, err := os.Pipe()
|
pr, pw, err := os.Pipe()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|||||||
@@ -334,7 +334,7 @@ func (s *Scheduler) executeTask(req *ExecutionRequest) (*ExecutionResult, error)
|
|||||||
}()
|
}()
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
|
||||||
s.logger.Infof("[Scheduler] 执行任务 %s (名称: %s, 类型: %s)", req.TaskID, req.Name, req.Type)
|
s.logger.Infof("[Scheduler] 开始执行: %s (#%s) [%s]", req.Name, req.TaskID, req.Type)
|
||||||
|
|
||||||
// 演示模式拦截
|
// 演示模式拦截
|
||||||
if constant.DemoMode {
|
if constant.DemoMode {
|
||||||
@@ -372,7 +372,7 @@ func (s *Scheduler) executeTask(req *ExecutionRequest) (*ExecutionResult, error)
|
|||||||
req.Command = utils.BuildMiseCommand(req.Command, req.Languages)
|
req.Command = utils.BuildMiseCommand(req.Command, req.Languages)
|
||||||
req.UseMise = false
|
req.UseMise = false
|
||||||
}
|
}
|
||||||
s.logger.Infof("[Scheduler] 实际执行命令: %s", req.Command)
|
s.logger.Infof("[Scheduler] 命令: %s", req.Command)
|
||||||
|
|
||||||
if s.config.Verbose {
|
if s.config.Verbose {
|
||||||
workDir := req.WorkDir
|
workDir := req.WorkDir
|
||||||
@@ -511,8 +511,8 @@ func (s *Scheduler) executeTask(req *ExecutionRequest) (*ExecutionResult, error)
|
|||||||
if execErr != nil {
|
if execErr != nil {
|
||||||
s.logger.Errorf("[Scheduler] 任务 %s 执行失败: %v", req.TaskID, execErr)
|
s.logger.Errorf("[Scheduler] 任务 %s 执行失败: %v", req.TaskID, execErr)
|
||||||
} else {
|
} else {
|
||||||
s.logger.Infof("[Scheduler] 任务 %s 执行完成 (状态: %s, 耗时: %dms)",
|
s.logger.Infof("[Scheduler] 执行完成: %s (#%s) [%s] (状态: %s, 耗时: %dms)",
|
||||||
req.TaskID, result.Status, result.Duration)
|
req.Name, req.TaskID, req.Type, result.Status, result.Duration)
|
||||||
}
|
}
|
||||||
|
|
||||||
return result, execErr
|
return result, execErr
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ func (h *ServerSchedulerHandler) OnTaskHeartbeat(req *executor.ExecutionRequest,
|
|||||||
|
|
||||||
// 每分钟打印一次任务还在运行的日志
|
// 每分钟打印一次任务还在运行的日志
|
||||||
if duration >= 60000 && (duration/60000 > (duration-3000)/60000) {
|
if duration >= 60000 && (duration/60000 > (duration-3000)/60000) {
|
||||||
logger.Infof("[Scheduler] 任务 #%s 仍在运行中... (已耗时: %v)",
|
logger.Infof("[Scheduler] 任务运行中... (#%s 已耗时: %v)",
|
||||||
req.TaskID, (time.Duration(duration) * time.Millisecond).Round(time.Second))
|
req.TaskID, (time.Duration(duration) * time.Millisecond).Round(time.Second))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ func (s *TaskLogService) CleanTaskLogs(taskID string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if deleted > 0 {
|
if deleted > 0 {
|
||||||
logger.Infof("[TaskLog] 清理任务 #%s 的 %d 条日志", taskID, deleted)
|
logger.Infof("[TaskLog] 清理旧日志: #%s 共 %d 条", taskID, deleted)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user