MCPcopy Create free account
hub / github.com/astercloud/aster / monitorTask

Method monitorTask

pkg/tools/builtin/task_manager.go:381–417  ·  view source on GitHub ↗

monitorTask 监控任务执行

(ctx context.Context, task *TaskInfo, cmd *exec.Cmd)

Source from the content-addressed store, hash-verified

379
380// monitorTask 监控任务执行
381func (tm *FileTaskManager) monitorTask(ctx context.Context, task *TaskInfo, cmd *exec.Cmd) {
382 defer func() {
383 // 发送清理信号
384 select {
385 case tm.cleanupChan <- task.ID:
386 default:
387 }
388 }()
389
390 // 等待命令完成
391 err := cmd.Wait()
392
393 tm.mu.Lock()
394 defer tm.mu.Unlock()
395
396 // 更新任务状态
397 now := time.Now()
398 task.EndTime = &now
399 task.Duration = now.Sub(task.StartTime)
400 task.LastUpdate = now
401
402 if err != nil {
403 exitErr := &exec.ExitError{}
404 if errors.As(err, &exitErr) {
405 task.ExitCode = exitErr.ExitCode()
406 task.Status = "failed"
407 } else {
408 task.Status = "failed"
409 task.ExitCode = -1
410 }
411 } else {
412 task.ExitCode = 0
413 task.Status = "completed"
414 }
415
416 _ = tm.saveTask(task)
417}
418
419// updateTaskStatus 更新任务状态
420func (tm *FileTaskManager) updateTaskStatus(task *TaskInfo) {

Callers 1

StartTaskMethod · 0.95

Calls 2

saveTaskMethod · 0.95
WaitMethod · 0.80

Tested by

no test coverage detected