WIP: 103268-job-task-progress #104185

Draft
Nitin-Rawat-1 wants to merge 19 commits from Nitin-Rawat-1/flamenco:103268-job-task-progress into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
6 changed files with 51 additions and 0 deletions
Showing only changes of commit bd86d0ff60 - Show all commits

View File

@ -369,6 +369,10 @@ func (f *Flamenco) ScheduleTask(e echo.Context) error {
return e.JSON(http.StatusOK, customisedTask)
}
// TODO: Complete the immplementation for the below function
func (f *Flamenco) TaskProgressUpdate(e echo.Context, taskID string) error {
return fmt.Errorf("")
}
func (f *Flamenco) TaskOutputProduced(e echo.Context, taskID string) error {
ctx := e.Request().Context()
filesize := e.Request().ContentLength

View File

@ -111,6 +111,11 @@ func jsFrameChunker(frameRange string, chunkSize int) ([]string, error) {
return chunks, nil
}
func jsCountChunkSize(chunk string) (int, error) {
frames, err := frameRangeExplode(chunk)
return len(frames), err
}
// Given a range of frames, return an array containing each frame number.
func frameRangeExplode(frameRange string) ([]int, error) {
// Store as map to avoid duplicate frames.

View File

@ -56,3 +56,38 @@ func TestFrameRangeExplode(t *testing.T) {
20, 21, 22, 23, 24, 25, 40,
}, frames)
}
func TestJSCountChunkSize(t *testing.T) {
tests := []struct {
name string
chunk string
want int
wantErr bool
}{
// Bad cases.
{"empty", "", 0, true},
{"negative", "-5", 0, true},
{"space", " ", 0, true},
{"no-comma", "5 10", 0, true},
{"no-numbers", "start-end", 0, true},
// Good cases.
{"single", "4", 1, false},
{"multiple", "4,5,10", 3, false},
{"onerange", "1-4", 4, false},
{"tworange", "1-4,10-12", 7, false},
{"overlap", "1-6,3-12", 12, false},
{"space-around", " 1-5\t", 5, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := jsCountChunkSize(tt.chunk)
if (err != nil) != tt.wantErr {
t.Errorf("jsCountChunkSize() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("jsCountChunkSize() = %v, want %v", got, tt.want)
}
})
}
}

View File

@ -140,6 +140,7 @@ func newGojaVM(registry *require.Registry) *goja.Runtime {
mustSet("alert", jsAlert)
mustSet("frameChunker", jsFrameChunker)
mustSet("formatTimestampLocal", jsFormatTimestampLocal)
mustSet("countChunkSize", jsCountChunkSize)
// Pre-import some useful modules.
registry.Enable(vm)

View File

@ -95,12 +95,14 @@ function authorRenderTasks(settings, renderDir, renderOutput) {
let renderTasks = [];
let chunks = frameChunker(settings.frames, settings.chunk_size);
for (let chunk of chunks) {
const numFrames = countChunkSize(chunk)
const task = author.Task(`render-${chunk}`, "blender");
const command = author.Command("blender-render", {
exe: "{blender}",
exeArgs: "{blenderArgs}",
argsBefore: [],
blendfile: settings.blendfile,
numFrames: numFrames,
args: [
"--render-output", path.join(renderDir, path.basename(renderOutput)),
"--render-format", settings.format,

View File

@ -27,6 +27,7 @@ type BlenderParameters struct {
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.
numFrames float64 // Additional CLI argument defined by the job compiler script, to define the total number of frame that are needed to be rendered.
}
// cmdBlender executes the "blender-render" command.
@ -138,6 +139,9 @@ func cmdBlenderRenderParams(logger zerolog.Logger, cmd api.Command) (BlenderPara
// Ignore the `ok` return value, as a missing exeArgs key is fine:
parameters.exeArgs, _ = cmdParameter[string](cmd, "exeArgs")
// Ignore the `ok` return value, as a missing numFrames key is fine:
parameters.numFrames, _ = cmdParameter[float64](cmd, "numFrames")
if parameters.argsBefore, ok = cmdParameterAsStrings(cmd, "argsBefore"); !ok {
logger.Warn().Interface("command", cmd).Msg("invalid 'argsBefore' parameter")
return parameters, NewParameterInvalidError("argsBefore", cmd, "cannot convert to list of strings")