Got very™ rudimentary job compilation working
This commit is contained in:
parent
da845daaaf
commit
c37e56e4bf
46
job_compilers/author.go
Normal file
46
job_compilers/author.go
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
package job_compilers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/dop251/goja"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Author allows scripts to author tasks and commands.
|
||||||
|
type Author struct {
|
||||||
|
runtime *goja.Runtime
|
||||||
|
}
|
||||||
|
|
||||||
|
type AuthoredTask struct {
|
||||||
|
Name string
|
||||||
|
Commands []AuthoredCommand
|
||||||
|
}
|
||||||
|
|
||||||
|
type AuthoredCommand struct {
|
||||||
|
Type string
|
||||||
|
Parameters map[string]string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *Author) Task(name string) (*AuthoredTask, error) {
|
||||||
|
at := AuthoredTask{
|
||||||
|
name,
|
||||||
|
make([]AuthoredCommand, 0),
|
||||||
|
}
|
||||||
|
return &at, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *Author) Command(cmdType string, parameters map[string]string) (*AuthoredCommand, error) {
|
||||||
|
ac := AuthoredCommand{cmdType, parameters}
|
||||||
|
return &ac, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func AuthorModule(r *goja.Runtime, module *goja.Object) {
|
||||||
|
a := &Author{
|
||||||
|
runtime: r,
|
||||||
|
}
|
||||||
|
obj := module.Get("exports").(*goja.Object)
|
||||||
|
obj.Set("Task", a.Task)
|
||||||
|
obj.Set("Command", a.Command)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (at *AuthoredTask) AddCommand(ac *AuthoredCommand) {
|
||||||
|
at.Commands = append(at.Commands, *ac)
|
||||||
|
}
|
@ -2,6 +2,7 @@ package job_compilers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/dop251/goja"
|
"github.com/dop251/goja"
|
||||||
"github.com/dop251/goja_nodejs/require"
|
"github.com/dop251/goja_nodejs/require"
|
||||||
@ -40,8 +41,9 @@ func Load() (*GojaJobCompiler, error) {
|
|||||||
registry := require.NewRegistry(require.WithLoader(staticFileLoader))
|
registry := require.NewRegistry(require.WithLoader(staticFileLoader))
|
||||||
registry.Enable(compiler.vm)
|
registry.Enable(compiler.vm)
|
||||||
|
|
||||||
// NodeJS has this module both importable and globally available.
|
registry.RegisterNativeModule("author", AuthorModule)
|
||||||
registry.RegisterNativeModule("process", ProcessModule)
|
registry.RegisterNativeModule("process", ProcessModule)
|
||||||
|
compiler.vm.Set("author", require.Require(compiler.vm, "author"))
|
||||||
compiler.vm.Set("process", require.Require(compiler.vm, "process"))
|
compiler.vm.Set("process", require.Require(compiler.vm, "process"))
|
||||||
|
|
||||||
return &compiler, nil
|
return &compiler, nil
|
||||||
@ -55,10 +57,6 @@ func newGojaVM() *goja.Runtime {
|
|||||||
log.Info().Interface("args", call.Arguments).Msg("print")
|
log.Info().Interface("args", call.Arguments).Msg("print")
|
||||||
return goja.Undefined()
|
return goja.Undefined()
|
||||||
})
|
})
|
||||||
vm.Set("create_task", func(call goja.FunctionCall) goja.Value {
|
|
||||||
log.Info().Interface("args", call.Arguments).Msg("create_task")
|
|
||||||
return goja.Undefined()
|
|
||||||
})
|
|
||||||
vm.Set("alert", func(call goja.FunctionCall) goja.Value {
|
vm.Set("alert", func(call goja.FunctionCall) goja.Value {
|
||||||
log.Warn().Interface("args", call.Arguments).Msg("alert")
|
log.Warn().Interface("args", call.Arguments).Msg("alert")
|
||||||
return goja.Undefined()
|
return goja.Undefined()
|
||||||
@ -67,10 +65,13 @@ func newGojaVM() *goja.Runtime {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Job struct {
|
type Job struct {
|
||||||
ID int64
|
JobID int64
|
||||||
Name string
|
Name string
|
||||||
JobType string
|
JobType string
|
||||||
Priority int8
|
Priority int8
|
||||||
|
|
||||||
|
Created time.Time
|
||||||
|
|
||||||
Settings JobSettings
|
Settings JobSettings
|
||||||
Metadata JobMetadata
|
Metadata JobMetadata
|
||||||
}
|
}
|
||||||
@ -84,11 +85,17 @@ func (c *GojaJobCompiler) Run(jobType string) error {
|
|||||||
return ErrJobTypeUnknown
|
return ErrJobTypeUnknown
|
||||||
}
|
}
|
||||||
|
|
||||||
|
created, err := time.Parse(time.RFC3339, "2022-01-03T18:53:00+01:00")
|
||||||
|
if err != nil {
|
||||||
|
panic("hard-coded timestamp is wrong")
|
||||||
|
}
|
||||||
|
|
||||||
job := Job{
|
job := Job{
|
||||||
ID: 327,
|
JobID: 327,
|
||||||
JobType: "blender-render",
|
JobType: "blender-render",
|
||||||
Priority: 50,
|
Priority: 50,
|
||||||
Name: "190_0030_A.lighting",
|
Name: "190_0030_A.lighting",
|
||||||
|
Created: created,
|
||||||
Settings: JobSettings{
|
Settings: JobSettings{
|
||||||
"blender_cmd": "{blender}",
|
"blender_cmd": "{blender}",
|
||||||
"chunk_size": 5,
|
"chunk_size": 5,
|
||||||
@ -108,7 +115,7 @@ func (c *GojaJobCompiler) Run(jobType string) error {
|
|||||||
}
|
}
|
||||||
c.vm.Set("job", &job)
|
c.vm.Set("job", &job)
|
||||||
|
|
||||||
_, err := c.vm.RunProgram(program)
|
_, err = c.vm.RunProgram(program)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,28 +2,44 @@ var path = require('path');
|
|||||||
|
|
||||||
print('Blender Render job submitted');
|
print('Blender Render job submitted');
|
||||||
print('job: ', job)
|
print('job: ', job)
|
||||||
print('running on platform', process.platform);
|
|
||||||
|
const { created, settings } = job;
|
||||||
|
|
||||||
// Determine the intermediate render output path.
|
// Determine the intermediate render output path.
|
||||||
function intermediate_path(render_path) {
|
function intermediatePath(render_path) {
|
||||||
const basename = path.basename(render_path);
|
const basename = path.basename(render_path);
|
||||||
const name = `${basename}__intermediate-${job.created}`;
|
const name = `${basename}__intermediate-${created}`;
|
||||||
return path.join(path.dirname(render_path), name);
|
return path.join(path.dirname(render_path), name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function frameChunker(frames, callback) {
|
||||||
|
callback('1-10');
|
||||||
|
callback('11-20');
|
||||||
|
callback('21-30');
|
||||||
|
}
|
||||||
|
|
||||||
// The render path contains a filename pattern, most likely '######' or
|
// The render path contains a filename pattern, most likely '######' or
|
||||||
// something similar. This has to be removed, so that we end up with
|
// something similar. This has to be removed, so that we end up with
|
||||||
// the directory that will contain the frames.
|
// the directory that will contain the frames.
|
||||||
const render_output = path.dirname(job.settings.render_output);
|
const renderOutput = path.dirname(settings.render_output);
|
||||||
print('render output', render_output);
|
const finalDir = path.dirname(renderOutput);
|
||||||
const final_dir = path.dirname(render_output);
|
const renderDir = intermediatePath(finalDir);
|
||||||
print('final dir ', final_dir);
|
|
||||||
const render_dir = intermediate_path(final_dir);
|
|
||||||
print('render dir ', render_dir);
|
|
||||||
|
|
||||||
// for (var i = 0; i < 5; i++) {
|
let renderTasks = [];
|
||||||
// create_task('task' + i, 'task' + i + ' description');
|
frameChunker(settings.frames, function(chunk) {
|
||||||
// }
|
const task = author.Task(`render-${chunk}`);
|
||||||
|
const command = author.Command('blender-render', {
|
||||||
|
cmd: settings.blender_cmd,
|
||||||
|
filepath: settings.filepath,
|
||||||
|
format: settings.format,
|
||||||
|
render_output: path.join(renderDir, path.basename(renderOutput)),
|
||||||
|
frames: chunk,
|
||||||
|
});
|
||||||
|
task.addCommand(command);
|
||||||
|
renderTasks.push(task);
|
||||||
|
});
|
||||||
|
|
||||||
print('done creating tasks');
|
print(`done creating ${renderTasks.length} tasks`);
|
||||||
|
for (const task of renderTasks) {
|
||||||
|
print(task);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user