157 lines
4.0 KiB
Go
157 lines
4.0 KiB
Go
// Package tasks provides task processing implementations.
|
|
package tasks
|
|
|
|
import (
|
|
"jiggablend/internal/runner/api"
|
|
"jiggablend/internal/runner/blender"
|
|
"jiggablend/internal/runner/encoding"
|
|
"jiggablend/internal/runner/workspace"
|
|
"jiggablend/pkg/executils"
|
|
"jiggablend/pkg/types"
|
|
)
|
|
|
|
// Processor handles a specific task type.
|
|
type Processor interface {
|
|
Process(ctx *Context) error
|
|
}
|
|
|
|
// Context provides task execution context.
|
|
type Context struct {
|
|
TaskID int64
|
|
JobID int64
|
|
JobName string
|
|
Frame int
|
|
TaskType string
|
|
WorkDir string
|
|
JobToken string
|
|
Metadata *types.BlendMetadata
|
|
|
|
Manager *api.ManagerClient
|
|
JobConn *api.JobConnection
|
|
Workspace *workspace.Manager
|
|
Blender *blender.Manager
|
|
Encoder *encoding.Selector
|
|
Processes *executils.ProcessTracker
|
|
}
|
|
|
|
// NewContext creates a new task context.
|
|
func NewContext(
|
|
taskID, jobID int64,
|
|
jobName string,
|
|
frame int,
|
|
taskType string,
|
|
workDir string,
|
|
jobToken string,
|
|
metadata *types.BlendMetadata,
|
|
manager *api.ManagerClient,
|
|
jobConn *api.JobConnection,
|
|
ws *workspace.Manager,
|
|
blenderMgr *blender.Manager,
|
|
encoder *encoding.Selector,
|
|
processes *executils.ProcessTracker,
|
|
) *Context {
|
|
return &Context{
|
|
TaskID: taskID,
|
|
JobID: jobID,
|
|
JobName: jobName,
|
|
Frame: frame,
|
|
TaskType: taskType,
|
|
WorkDir: workDir,
|
|
JobToken: jobToken,
|
|
Metadata: metadata,
|
|
Manager: manager,
|
|
JobConn: jobConn,
|
|
Workspace: ws,
|
|
Blender: blenderMgr,
|
|
Encoder: encoder,
|
|
Processes: processes,
|
|
}
|
|
}
|
|
|
|
// Log sends a log entry to the manager.
|
|
func (c *Context) Log(level types.LogLevel, message string) {
|
|
if c.JobConn != nil {
|
|
c.JobConn.Log(c.TaskID, level, message)
|
|
}
|
|
}
|
|
|
|
// Info logs an info message.
|
|
func (c *Context) Info(message string) {
|
|
c.Log(types.LogLevelInfo, message)
|
|
}
|
|
|
|
// Warn logs a warning message.
|
|
func (c *Context) Warn(message string) {
|
|
c.Log(types.LogLevelWarn, message)
|
|
}
|
|
|
|
// Error logs an error message.
|
|
func (c *Context) Error(message string) {
|
|
c.Log(types.LogLevelError, message)
|
|
}
|
|
|
|
// Progress sends a progress update.
|
|
func (c *Context) Progress(progress float64) {
|
|
if c.JobConn != nil {
|
|
c.JobConn.Progress(c.TaskID, progress)
|
|
}
|
|
}
|
|
|
|
// OutputUploaded notifies that an output file was uploaded.
|
|
func (c *Context) OutputUploaded(fileName string) {
|
|
if c.JobConn != nil {
|
|
c.JobConn.OutputUploaded(c.TaskID, fileName)
|
|
}
|
|
}
|
|
|
|
// Complete sends task completion.
|
|
func (c *Context) Complete(success bool, errorMsg error) {
|
|
if c.JobConn != nil {
|
|
c.JobConn.Complete(c.TaskID, success, errorMsg)
|
|
}
|
|
}
|
|
|
|
// GetOutputFormat returns the output format from metadata or default.
|
|
func (c *Context) GetOutputFormat() string {
|
|
if c.Metadata != nil && c.Metadata.RenderSettings.OutputFormat != "" {
|
|
return c.Metadata.RenderSettings.OutputFormat
|
|
}
|
|
return "PNG"
|
|
}
|
|
|
|
// GetFrameRate returns the frame rate from metadata or default.
|
|
func (c *Context) GetFrameRate() float64 {
|
|
if c.Metadata != nil && c.Metadata.RenderSettings.FrameRate > 0 {
|
|
return c.Metadata.RenderSettings.FrameRate
|
|
}
|
|
return 24.0
|
|
}
|
|
|
|
// GetBlenderVersion returns the Blender version from metadata.
|
|
func (c *Context) GetBlenderVersion() string {
|
|
if c.Metadata != nil {
|
|
return c.Metadata.BlenderVersion
|
|
}
|
|
return ""
|
|
}
|
|
|
|
// ShouldUnhideObjects returns whether to unhide objects.
|
|
func (c *Context) ShouldUnhideObjects() bool {
|
|
return c.Metadata != nil && c.Metadata.UnhideObjects != nil && *c.Metadata.UnhideObjects
|
|
}
|
|
|
|
// ShouldEnableExecution returns whether to enable auto-execution.
|
|
func (c *Context) ShouldEnableExecution() bool {
|
|
return c.Metadata != nil && c.Metadata.EnableExecution != nil && *c.Metadata.EnableExecution
|
|
}
|
|
|
|
// ShouldPreserveHDR returns whether to preserve HDR range for EXR encoding.
|
|
func (c *Context) ShouldPreserveHDR() bool {
|
|
return c.Metadata != nil && c.Metadata.PreserveHDR != nil && *c.Metadata.PreserveHDR
|
|
}
|
|
|
|
// ShouldPreserveAlpha returns whether to preserve alpha channel for EXR encoding.
|
|
func (c *Context) ShouldPreserveAlpha() bool {
|
|
return c.Metadata != nil && c.Metadata.PreserveAlpha != nil && *c.Metadata.PreserveAlpha
|
|
}
|