Fix some linter warnings
No functional changes.
This commit is contained in:
parent
289bcf6414
commit
6520dc2d66
@ -30,18 +30,15 @@ import (
|
|||||||
func (f *Flamenco) GetJobTypes(e echo.Context) error {
|
func (f *Flamenco) GetJobTypes(e echo.Context) error {
|
||||||
// Some helper functions because Go doesn't allow taking the address of a literal.
|
// Some helper functions because Go doesn't allow taking the address of a literal.
|
||||||
defaultString := func(s string) *interface{} {
|
defaultString := func(s string) *interface{} {
|
||||||
var iValue interface{}
|
var iValue interface{} = s
|
||||||
iValue = s
|
|
||||||
return &iValue
|
return &iValue
|
||||||
}
|
}
|
||||||
defaultInt32 := func(i int32) *interface{} {
|
defaultInt32 := func(i int32) *interface{} {
|
||||||
var iValue interface{}
|
var iValue interface{} = i
|
||||||
iValue = i
|
|
||||||
return &iValue
|
return &iValue
|
||||||
}
|
}
|
||||||
defaultBool := func(b bool) *interface{} {
|
defaultBool := func(b bool) *interface{} {
|
||||||
var iValue interface{}
|
var iValue interface{} = b
|
||||||
iValue = b
|
|
||||||
return &iValue
|
return &iValue
|
||||||
}
|
}
|
||||||
boolPtr := func(b bool) *bool {
|
boolPtr := func(b bool) *bool {
|
||||||
|
@ -58,8 +58,8 @@ func (f *Flamenco) ScheduleTask(e echo.Context) error {
|
|||||||
return e.JSON(http.StatusOK, &api.AssignedTask{
|
return e.JSON(http.StatusOK, &api.AssignedTask{
|
||||||
Id: uuid.New().String(),
|
Id: uuid.New().String(),
|
||||||
Commands: []api.Command{
|
Commands: []api.Command{
|
||||||
{"echo", echo.Map{"payload": "Simon says \"Shaders!\""}},
|
{Name: "echo", Settings: echo.Map{"payload": "Simon says \"Shaders!\""}},
|
||||||
{"blender", echo.Map{"blender_cmd": "/shared/bin/blender"}},
|
{Name: "blender", Settings: echo.Map{"blender_cmd": "/shared/bin/blender"}},
|
||||||
},
|
},
|
||||||
Job: uuid.New().String(),
|
Job: uuid.New().String(),
|
||||||
JobPriority: 50,
|
JobPriority: 50,
|
||||||
|
@ -76,13 +76,21 @@ func (a *Author) Command(cmdType string, parameters map[string]string) (*Authore
|
|||||||
return &ac, nil
|
return &ac, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AuthorModule exports the Author module members to Goja.
|
||||||
func AuthorModule(r *goja.Runtime, module *goja.Object) {
|
func AuthorModule(r *goja.Runtime, module *goja.Object) {
|
||||||
a := &Author{
|
a := &Author{
|
||||||
runtime: r,
|
runtime: r,
|
||||||
}
|
}
|
||||||
obj := module.Get("exports").(*goja.Object)
|
obj := module.Get("exports").(*goja.Object)
|
||||||
obj.Set("Task", a.Task)
|
mustExport := func(name string, value interface{}) {
|
||||||
obj.Set("Command", a.Command)
|
err := obj.Set(name, value)
|
||||||
|
if err != nil {
|
||||||
|
log.Panic().Err(err).Msgf("unable to register '%s' in Goja 'author' module", name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mustExport("Task", a.Task)
|
||||||
|
mustExport("Command", a.Command)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (aj *AuthoredJob) AddTask(at *AuthoredTask) {
|
func (aj *AuthoredJob) AddTask(at *AuthoredTask) {
|
||||||
|
@ -75,21 +75,22 @@ func (c *GojaJobCompiler) newGojaVM() *goja.Runtime {
|
|||||||
vm := goja.New()
|
vm := goja.New()
|
||||||
vm.SetFieldNameMapper(goja.UncapFieldNameMapper())
|
vm.SetFieldNameMapper(goja.UncapFieldNameMapper())
|
||||||
|
|
||||||
|
mustSet := func(name string, value interface{}) {
|
||||||
|
err := vm.Set(name, value)
|
||||||
|
if err != nil {
|
||||||
|
log.Panic().Err(err).Msgf("unable to register '%s' in Goja VM", name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Set some global functions for script debugging purposes.
|
// Set some global functions for script debugging purposes.
|
||||||
vm.Set("print", func(call goja.FunctionCall) goja.Value {
|
mustSet("print", jsPrint)
|
||||||
log.Info().Interface("args", call.Arguments).Msg("print")
|
mustSet("alert", jsAlert)
|
||||||
return goja.Undefined()
|
|
||||||
})
|
|
||||||
vm.Set("alert", func(call goja.FunctionCall) goja.Value {
|
|
||||||
log.Warn().Interface("args", call.Arguments).Msg("alert")
|
|
||||||
return goja.Undefined()
|
|
||||||
})
|
|
||||||
|
|
||||||
// Pre-import some useful modules.
|
// Pre-import some useful modules.
|
||||||
c.registry.Enable(vm)
|
c.registry.Enable(vm)
|
||||||
vm.Set("author", require.Require(vm, "author"))
|
mustSet("author", require.Require(vm, "author"))
|
||||||
vm.Set("path", require.Require(vm, "path"))
|
mustSet("path", require.Require(vm, "path"))
|
||||||
vm.Set("process", require.Require(vm, "process"))
|
mustSet("process", require.Require(vm, "process"))
|
||||||
|
|
||||||
return vm
|
return vm
|
||||||
}
|
}
|
||||||
|
36
internal/manager/job_compilers/js_globals.go
Normal file
36
internal/manager/job_compilers/js_globals.go
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package job_compilers
|
||||||
|
|
||||||
|
/* ***** 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 <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* ***** END GPL LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/dop251/goja"
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
func jsPrint(call goja.FunctionCall) goja.Value {
|
||||||
|
log.Info().Interface("args", call.Arguments).Msg("print")
|
||||||
|
return goja.Undefined()
|
||||||
|
}
|
||||||
|
|
||||||
|
func jsAlert(call goja.FunctionCall) goja.Value {
|
||||||
|
log.Warn().Interface("args", call.Arguments).Msg("alert")
|
||||||
|
return goja.Undefined()
|
||||||
|
}
|
@ -24,15 +24,24 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/dop251/goja"
|
"github.com/dop251/goja"
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// PathModule provides file path manipulation functions by wrapping Go's `path`.
|
// PathModule provides file path manipulation functions by wrapping Go's `path`.
|
||||||
func PathModule(r *goja.Runtime, module *goja.Object) {
|
func PathModule(r *goja.Runtime, module *goja.Object) {
|
||||||
obj := module.Get("exports").(*goja.Object)
|
obj := module.Get("exports").(*goja.Object)
|
||||||
obj.Set("basename", filepath.Base)
|
|
||||||
obj.Set("dirname", filepath.Dir)
|
mustExport := func(name string, value interface{}) {
|
||||||
obj.Set("join", filepath.Join)
|
err := obj.Set(name, value)
|
||||||
obj.Set("stem", Stem)
|
if err != nil {
|
||||||
|
log.Panic().Err(err).Msgf("unable to register '%s' in Goja 'path' module", name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mustExport("basename", filepath.Base)
|
||||||
|
mustExport("dirname", filepath.Dir)
|
||||||
|
mustExport("join", filepath.Join)
|
||||||
|
mustExport("stem", Stem)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Stem(fpath string) string {
|
func Stem(fpath string) string {
|
||||||
|
@ -25,6 +25,7 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"github.com/dop251/goja"
|
"github.com/dop251/goja"
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Process implements a subset of the built-in NodeJS process object.
|
// Process implements a subset of the built-in NodeJS process object.
|
||||||
@ -43,10 +44,18 @@ func ProcessModule(r *goja.Runtime, module *goja.Object) {
|
|||||||
runtime: r,
|
runtime: r,
|
||||||
}
|
}
|
||||||
obj := module.Get("exports").(*goja.Object)
|
obj := module.Get("exports").(*goja.Object)
|
||||||
obj.Set("cwd", p.cwd)
|
|
||||||
|
mustExport := func(name string, value interface{}) {
|
||||||
|
err := obj.Set(name, value)
|
||||||
|
if err != nil {
|
||||||
|
log.Panic().Err(err).Msgf("unable to register '%s' in Goja 'process' module", name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mustExport("cwd", p.cwd)
|
||||||
|
|
||||||
// To get a list of possible values of runtime.GOOS, run `go tool dist list`.
|
// To get a list of possible values of runtime.GOOS, run `go tool dist list`.
|
||||||
// The NodeJS values are documented on https://nodejs.org/api/process.html#processplatform
|
// The NodeJS values are documented on https://nodejs.org/api/process.html#processplatform
|
||||||
// Both lists are equal enough to just use runtime.GOOS here.
|
// Both lists are equal enough to just use runtime.GOOS here.
|
||||||
obj.Set("platform", runtime.GOOS)
|
mustExport("platform", runtime.GOOS)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user