Refactor imports and clean up whitespace in API and runner client files. Update auth package references to use the new package structure. Improve mutex usage in the runner client for better concurrency handling.
This commit is contained in:
@@ -20,8 +20,9 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
"fuego/pkg/types"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
// Client represents a runner client
|
||||
@@ -35,7 +36,7 @@ type Client struct {
|
||||
runnerSecret string
|
||||
managerSecret string
|
||||
wsConn *websocket.Conn
|
||||
wsConnMu sync.Mutex
|
||||
wsConnMu sync.RWMutex
|
||||
stopChan chan struct{}
|
||||
}
|
||||
|
||||
@@ -144,7 +145,7 @@ func (c *Client) ConnectWebSocket() error {
|
||||
h := hmac.New(sha256.New, []byte(c.runnerSecret))
|
||||
h.Write([]byte(message))
|
||||
signature := hex.EncodeToString(h.Sum(nil))
|
||||
|
||||
|
||||
// Convert HTTP URL to WebSocket URL
|
||||
wsURL := strings.Replace(c.managerURL, "http://", "ws://", 1)
|
||||
wsURL = strings.Replace(wsURL, "https://", "wss://", 1)
|
||||
@@ -268,8 +269,8 @@ func (c *Client) handleTaskAssignment(msg map[string]interface{}) {
|
||||
|
||||
// Convert to task map format
|
||||
taskMap := map[string]interface{}{
|
||||
"id": taskID,
|
||||
"job_id": jobID,
|
||||
"id": taskID,
|
||||
"job_id": jobID,
|
||||
"frame_start": frameStart,
|
||||
"frame_end": frameEnd,
|
||||
}
|
||||
@@ -402,7 +403,7 @@ func (c *Client) processTask(task map[string]interface{}, jobName, outputFormat
|
||||
// Step: render_blender
|
||||
c.sendStepUpdate(taskID, "render_blender", types.StepStatusRunning, "")
|
||||
c.sendLog(taskID, types.LogLevelInfo, fmt.Sprintf("Starting Blender render for frame %d...", frameStart), "render_blender")
|
||||
|
||||
|
||||
// Execute Blender
|
||||
cmd := exec.Command("blender", "-b", blendFile, "-o", outputPattern, "-f", fmt.Sprintf("%d", frameStart))
|
||||
cmd.Dir = workDir
|
||||
@@ -432,7 +433,7 @@ func (c *Client) processTask(task map[string]interface{}, jobName, outputFormat
|
||||
}
|
||||
c.sendStepUpdate(taskID, uploadStepName, types.StepStatusRunning, "")
|
||||
c.sendLog(taskID, types.LogLevelInfo, "Uploading output file...", uploadStepName)
|
||||
|
||||
|
||||
outputPath, err := c.uploadFile(jobID, outputFile)
|
||||
if err != nil {
|
||||
errMsg := fmt.Sprintf("failed to upload output: %w", err)
|
||||
@@ -446,7 +447,7 @@ func (c *Client) processTask(task map[string]interface{}, jobName, outputFormat
|
||||
// Step: complete
|
||||
c.sendStepUpdate(taskID, "complete", types.StepStatusRunning, "")
|
||||
c.sendLog(taskID, types.LogLevelInfo, "Task completed successfully", "complete")
|
||||
|
||||
|
||||
// Mark task as complete
|
||||
if err := c.completeTask(taskID, outputPath, true, ""); err != nil {
|
||||
c.sendStepUpdate(taskID, "complete", types.StepStatusFailed, err.Error())
|
||||
@@ -731,7 +732,7 @@ func (c *Client) uploadFile(jobID int64, filePath string) (string, error) {
|
||||
// Create multipart form
|
||||
var buf bytes.Buffer
|
||||
formWriter := multipart.NewWriter(&buf)
|
||||
|
||||
|
||||
part, err := formWriter.CreateFormFile("file", filepath.Base(filePath))
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to create form file: %w", err)
|
||||
@@ -813,4 +814,3 @@ func (c *Client) sendTaskComplete(taskID int64, outputPath string, success bool,
|
||||
}
|
||||
return fmt.Errorf("WebSocket not connected, cannot complete task")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user