fix(delivery): use unique pending AWX job placeholders
This commit is contained in:
@@ -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)})
|
lines = append(lines, taskLogLine{Time: formatTaskLogTime(event.CreatedAt), Message: "[" + event.ToState + "] " + event.Message, Class: classForTaskStatus(event.ToState)})
|
||||||
}
|
}
|
||||||
var execution model.ExecutionJob
|
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)
|
stdout, stdoutErr := h.delivery.AWXJobStdout(c.Request.Context(), execution.ExecutorJobID)
|
||||||
if stdoutErr != nil {
|
if stdoutErr != nil {
|
||||||
lines = append(lines, taskLogLine{Time: formatTaskLogTime(time.Now()), Message: "[awx] stdout fetch failed: " + stdoutErr.Error(), Class: "err"})
|
lines = append(lines, taskLogLine{Time: formatTaskLogTime(time.Now()), Message: "[awx] stdout fetch failed: " + stdoutErr.Error(), Class: "err"})
|
||||||
|
|||||||
@@ -761,7 +761,7 @@ func (s *DeliveryService) CreateExecution(ctx context.Context, taskID, payloadHa
|
|||||||
}
|
}
|
||||||
// Persist execution record BEFORE launching AWX to ensure crash recovery.
|
// Persist execution record BEFORE launching AWX to ensure crash recovery.
|
||||||
now := time.Now()
|
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 {
|
if err := s.db.WithContext(ctx).Create(&execution).Error; err != nil {
|
||||||
return nil, false, err
|
return nil, false, err
|
||||||
}
|
}
|
||||||
@@ -1119,3 +1119,7 @@ func (s *DeliveryService) Run(ctx context.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func pendingExecutorJobID(taskID string) string {
|
||||||
|
return "pending:" + taskID
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user