Refactor runner and API components to remove IP address handling. Update client and server logic to streamline runner registration and task distribution. Introduce write mutexes for connection management to enhance concurrency control. Clean up whitespace and improve code readability across multiple files.
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
package runner
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"archive/tar"
|
||||
"bufio"
|
||||
"bytes"
|
||||
_ "embed"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
@@ -33,7 +33,6 @@ type Client struct {
|
||||
managerURL string
|
||||
name string
|
||||
hostname string
|
||||
ipAddress string
|
||||
httpClient *http.Client
|
||||
runnerID int64
|
||||
runnerSecret string
|
||||
@@ -58,12 +57,11 @@ type Client struct {
|
||||
}
|
||||
|
||||
// NewClient creates a new runner client
|
||||
func NewClient(managerURL, name, hostname, ipAddress string) *Client {
|
||||
func NewClient(managerURL, name, hostname string) *Client {
|
||||
return &Client{
|
||||
managerURL: managerURL,
|
||||
name: name,
|
||||
hostname: hostname,
|
||||
ipAddress: ipAddress,
|
||||
httpClient: &http.Client{Timeout: 30 * time.Second},
|
||||
longRunningClient: &http.Client{Timeout: 0}, // No timeout for long-running operations (context downloads, file uploads/downloads)
|
||||
stopChan: make(chan struct{}),
|
||||
@@ -412,7 +410,6 @@ func (c *Client) Register(registrationToken string) (int64, string, string, erro
|
||||
req := map[string]interface{}{
|
||||
"name": c.name,
|
||||
"hostname": c.hostname,
|
||||
"ip_address": c.ipAddress,
|
||||
"capabilities": string(capabilitiesJSON),
|
||||
"registration_token": registrationToken,
|
||||
}
|
||||
@@ -983,8 +980,8 @@ func (c *Client) processTask(task map[string]interface{}, jobName string, output
|
||||
// Clean up expired cache entries periodically
|
||||
c.cleanupExpiredContextCache()
|
||||
|
||||
// Download context tar
|
||||
contextPath := filepath.Join(workDir, "context.tar")
|
||||
// Download context tar
|
||||
contextPath := filepath.Join(workDir, "context.tar")
|
||||
if err := c.downloadJobContext(jobID, contextPath); err != nil {
|
||||
c.sendStepUpdate(taskID, "download", types.StepStatusFailed, err.Error())
|
||||
return fmt.Errorf("failed to download context: %w", err)
|
||||
@@ -1091,19 +1088,19 @@ func (c *Client) processTask(task map[string]interface{}, jobName string, output
|
||||
// This script will override the blend file's settings based on job metadata
|
||||
formatFilePath := filepath.Join(workDir, "output_format.txt")
|
||||
renderSettingsFilePath := filepath.Join(workDir, "render_settings.json")
|
||||
|
||||
|
||||
// Check if unhide_objects is enabled
|
||||
unhideObjects := false
|
||||
if jobMetadata != nil && jobMetadata.UnhideObjects != nil && *jobMetadata.UnhideObjects {
|
||||
unhideObjects = true
|
||||
}
|
||||
|
||||
|
||||
// Build unhide code conditionally from embedded script
|
||||
unhideCode := ""
|
||||
if unhideObjects {
|
||||
unhideCode = scripts.UnhideObjects
|
||||
}
|
||||
|
||||
|
||||
// Load template and replace placeholders
|
||||
scriptContent := scripts.RenderBlenderTemplate
|
||||
scriptContent = strings.ReplaceAll(scriptContent, "{{UNHIDE_CODE}}", unhideCode)
|
||||
@@ -3016,8 +3013,8 @@ func (c *Client) processMetadataTask(task map[string]interface{}, jobID int64, i
|
||||
c.sendStepUpdate(taskID, "download", types.StepStatusRunning, "")
|
||||
c.sendLog(taskID, types.LogLevelInfo, "Downloading job context...", "download")
|
||||
|
||||
// Download context tar
|
||||
contextPath := filepath.Join(workDir, "context.tar")
|
||||
// Download context tar
|
||||
contextPath := filepath.Join(workDir, "context.tar")
|
||||
if err := c.downloadJobContext(jobID, contextPath); err != nil {
|
||||
c.sendStepUpdate(taskID, "download", types.StepStatusFailed, err.Error())
|
||||
return fmt.Errorf("failed to download context: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user