diff --git a/server/internal/handler/task_log.go b/server/internal/handler/task_log.go index e935053..8572e46 100644 --- a/server/internal/handler/task_log.go +++ b/server/internal/handler/task_log.go @@ -138,7 +138,7 @@ func (h *TaskLogHandler) getAWXTask(c *gin.Context, taskID string, userID uint64 lines = append(lines, taskLogLine{Time: formatTaskLogTime(event.CreatedAt), Message: "[" + event.ToState + "] " + event.Message, Class: classForTaskStatus(event.ToState)}) } var execution model.ExecutionJob - if err := h.db.WithContext(c.Request.Context()).Where("task_id = ?", task.ID).First(&execution).Error; err == nil && execution.ExecutorJobID != "" && execution.ExecutorJobID != "pending" { + if err := h.db.WithContext(c.Request.Context()).Where("task_id = ?", task.ID).First(&execution).Error; err == nil && execution.ExecutorJobID != "" && execution.ExecutorJobID != "pending" && !strings.HasPrefix(execution.ExecutorJobID, "pending:") { stdout, stdoutErr := h.delivery.AWXJobStdout(c.Request.Context(), execution.ExecutorJobID) if stdoutErr != nil { lines = append(lines, taskLogLine{Time: formatTaskLogTime(time.Now()), Message: "[awx] stdout fetch failed: " + stdoutErr.Error(), Class: "err"}) diff --git a/server/internal/service/delivery.go b/server/internal/service/delivery.go index c60086f..5325443 100644 --- a/server/internal/service/delivery.go +++ b/server/internal/service/delivery.go @@ -761,7 +761,7 @@ func (s *DeliveryService) CreateExecution(ctx context.Context, taskID, payloadHa } // Persist execution record BEFORE launching AWX to ensure crash recovery. now := time.Now() - execution := model.ExecutionJob{TaskID: task.ID, IdempotencyKey: task.IdempotencyKey, ExecutorJobID: "pending", Status: "launching", StartedAt: &now} + execution := model.ExecutionJob{TaskID: task.ID, IdempotencyKey: task.IdempotencyKey, ExecutorJobID: pendingExecutorJobID(task.ID), Status: "launching", StartedAt: &now} if err := s.db.WithContext(ctx).Create(&execution).Error; err != nil { return nil, false, err } @@ -1119,3 +1119,7 @@ func (s *DeliveryService) Run(ctx context.Context) { } } } + +func pendingExecutorJobID(taskID string) string { + return "pending:" + taskID +}