Refactor error handling and improve code formatting in runners.go. Replace fmt.Errorf with errors.New for better error management. Clean up whitespace and enhance readability in various API response structures.
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
@@ -295,10 +296,10 @@ func (s *Server) handleUpdateTaskStep(w http.ResponseWriter, r *http.Request) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
// Broadcast step update to frontend
|
// Broadcast step update to frontend
|
||||||
s.broadcastTaskUpdate(jobID, taskID, "step_update", map[string]interface{}{
|
s.broadcastTaskUpdate(jobID, taskID, "step_update", map[string]interface{}{
|
||||||
"step_id": stepID,
|
"step_id": stepID,
|
||||||
"step_name": req.StepName,
|
"step_name": req.StepName,
|
||||||
"status": req.Status,
|
"status": req.Status,
|
||||||
"duration_ms": req.DurationMs,
|
"duration_ms": req.DurationMs,
|
||||||
"error_message": req.ErrorMessage,
|
"error_message": req.ErrorMessage,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -338,7 +339,7 @@ func (s *Server) handleDownloadJobContext(w http.ResponseWriter, r *http.Request
|
|||||||
// Set appropriate headers for tar file
|
// Set appropriate headers for tar file
|
||||||
w.Header().Set("Content-Type", "application/x-tar")
|
w.Header().Set("Content-Type", "application/x-tar")
|
||||||
w.Header().Set("Content-Disposition", "attachment; filename=context.tar")
|
w.Header().Set("Content-Disposition", "attachment; filename=context.tar")
|
||||||
|
|
||||||
// Stream the file to the response
|
// Stream the file to the response
|
||||||
io.Copy(w, file)
|
io.Copy(w, file)
|
||||||
}
|
}
|
||||||
@@ -1153,8 +1154,8 @@ func (s *Server) updateJobStatusFromTasks(jobID int64) {
|
|||||||
}
|
}
|
||||||
// Broadcast job update via WebSocket
|
// Broadcast job update via WebSocket
|
||||||
s.broadcastJobUpdate(jobID, "job_update", map[string]interface{}{
|
s.broadcastJobUpdate(jobID, "job_update", map[string]interface{}{
|
||||||
"status": jobStatus,
|
"status": jobStatus,
|
||||||
"progress": progress,
|
"progress": progress,
|
||||||
"completed_at": now,
|
"completed_at": now,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -1184,7 +1185,7 @@ func (s *Server) updateJobStatusFromTasks(jobID int64) {
|
|||||||
// Broadcast that a new task was added
|
// Broadcast that a new task was added
|
||||||
log.Printf("Broadcasting task_added for job %d: video generation task %d", jobID, videoTaskID)
|
log.Printf("Broadcasting task_added for job %d: video generation task %d", jobID, videoTaskID)
|
||||||
s.broadcastTaskUpdate(jobID, videoTaskID, "task_added", map[string]interface{}{
|
s.broadcastTaskUpdate(jobID, videoTaskID, "task_added", map[string]interface{}{
|
||||||
"task_id": videoTaskID,
|
"task_id": videoTaskID,
|
||||||
"task_type": types.TaskTypeVideoGeneration,
|
"task_type": types.TaskTypeVideoGeneration,
|
||||||
})
|
})
|
||||||
// Update job status to ensure it's marked as running (has pending video task)
|
// Update job status to ensure it's marked as running (has pending video task)
|
||||||
@@ -1790,7 +1791,7 @@ func (s *Server) assignTaskToRunner(runnerID int64, taskID int64) error {
|
|||||||
types.TaskStatusPending, taskID,
|
types.TaskStatusPending, taskID,
|
||||||
)
|
)
|
||||||
s.logTaskEvent(taskID, nil, types.LogLevelError, errMsg, "")
|
s.logTaskEvent(taskID, nil, types.LogLevelError, errMsg, "")
|
||||||
return fmt.Errorf(errMsg)
|
return errors.New(errMsg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: Task is already assigned in database by the atomic update in distributeTasksToRunners
|
// Note: Task is already assigned in database by the atomic update in distributeTasksToRunners
|
||||||
|
|||||||
Reference in New Issue
Block a user