diff --git a/internal/manager/job_compilers/job_compilers_test.go b/internal/manager/job_compilers/job_compilers_test.go index ec50290e..e4579340 100644 --- a/internal/manager/job_compilers/job_compilers_test.go +++ b/internal/manager/job_compilers/job_compilers_test.go @@ -114,9 +114,10 @@ func TestSimpleBlenderRenderHappy(t *testing.T) { assert.Equal(t, 1, len(t0.Commands)) assert.Equal(t, "blender-render", t0.Commands[0].Type) assert.EqualValues(t, AuthoredCommandParameters{ - "exe": "{blender}", - "blendfile": settings["filepath"].(string), - "args": expectCliArgs, + "exe": "{blender}", + "blendfile": settings["filepath"].(string), + "args": expectCliArgs, + "argsBefore": make([]interface{}, 0), }, t0.Commands[0].Parameters) tVideo := aj.Tasks[4] // This should be a video encoding task diff --git a/internal/manager/job_compilers/scripts/simple_blender_render.js b/internal/manager/job_compilers/scripts/simple_blender_render.js index 9ebbf54d..dae8818d 100644 --- a/internal/manager/job_compilers/scripts/simple_blender_render.js +++ b/internal/manager/job_compilers/scripts/simple_blender_render.js @@ -93,6 +93,7 @@ function authorRenderTasks(settings, renderDir, renderOutput) { const task = author.Task(`render-${chunk}`, "blender"); const command = author.Command("blender-render", { exe: settings.blender_cmd, + argsBefore: [], blendfile: settings.filepath, args: [ "--render-output", path.join(renderDir, path.basename(renderOutput)), diff --git a/internal/worker/command_blender.go b/internal/worker/command_blender.go new file mode 100644 index 00000000..09766f15 --- /dev/null +++ b/internal/worker/command_blender.go @@ -0,0 +1,72 @@ +package worker + +/* ***** BEGIN GPL LICENSE BLOCK ***** + * + * Original Code Copyright (C) 2022 Blender Foundation. + * + * This file is part of Flamenco. + * + * Flamenco is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later + * version. + * + * Flamenco is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * Flamenco. If not, see . + * + * ***** END GPL LICENSE BLOCK ***** */ + +/* This file contains the commands in the "blender" type group. */ + +import ( + "context" + "fmt" + "os/exec" + + "github.com/rs/zerolog" + "gitlab.com/blender/flamenco-ng-poc/pkg/api" +) + +type BlenderSettings struct { + exe string // Expansion of `{blender}`: executable path + its CLI parameters defined by the Manager. + argsBefore []string // Additional CLI arguments defined by the job compiler script, to go before the blend file name. + blendfile string // Path of the file to open. + args []string // Additional CLI arguments defined by the job compiler script, to go after the blend file name. +} + +// cmdBlender executes the "blender-render" command. +func (ce *CommandExecutor) cmdBlenderRender(ctx context.Context, logger zerolog.Logger, taskID string, cmd api.Command) error { + settings := BlenderSettings{ + exe: cmd.Settings["exe"].(string), + argsBefore: cmd.Settings["argsBefore"].([]string), + blendfile: cmd.Settings["blendfile"].(string), + args: cmd.Settings["args"].([]string), + } + if settings.exe == "" { + logger.Warn().Interface("command", cmd).Msg("missing 'exe' setting") + return fmt.Errorf("missing 'exe' setting: %+v", cmd) + } + if settings.blendfile == "" { + logger.Warn().Interface("command", cmd).Msg("missing 'blendfile' setting") + return fmt.Errorf("missing 'blendfile' setting: %+v", cmd) + } + + cliArgs := make([]string, 0) + cliArgs = append(cliArgs, settings.argsBefore...) + cliArgs = append(cliArgs, settings.blendfile) + cliArgs = append(cliArgs, settings.args...) + execCmd := exec.CommandContext(ctx, settings.exe, cliArgs...) + logger.Info(). + Str("cmdName", cmd.Name). + Str("execCmd", execCmd.String()). + Msg("going to execute Blender") + + // if err := ce.listener.LogProduced(ctx, taskID, fmt.Sprintf("echo: %q", messageStr)); err != nil { + // return err + // } + return nil +} diff --git a/internal/worker/command_exe.go b/internal/worker/command_exe.go index 36a1fad4..e880b7d2 100644 --- a/internal/worker/command_exe.go +++ b/internal/worker/command_exe.go @@ -68,8 +68,9 @@ func NewCommandExecutor(listener CommandListener, timeService TimeService) *Comm // switch statement) makes it possible to do things like reporting the list of // supported commands. ce.registry = map[string]commandCallable{ - "echo": ce.cmdEcho, - "sleep": ce.cmdSleep, + "echo": ce.cmdEcho, + "sleep": ce.cmdSleep, + "blender-render": ce.cmdBlenderRender, } return ce