Manager: ignore small JS files

Empty (or almost-empty) JS files are ignored by the job compiler.
This commit is contained in:
Sybren A. Stüvel 2022-06-20 17:14:06 +02:00
parent 7a89c07fc9
commit 89fdc45b45
3 changed files with 9 additions and 0 deletions

View File

@ -49,6 +49,14 @@ func (s *Service) loadScriptsFrom(filesystem fs.FS) error {
continue
}
if len(script_bytes) < 8 {
log.Debug().
Str("script", filename).
Int("fileSizeBytes", len(script_bytes)).
Msg("ignoring tiny JS file, it is unlikely to be a job compiler script")
continue
}
program, err := goja.Compile(filename, string(script_bytes), true)
if err != nil {
log.Error().Err(err).Str("filename", filename).Msg("failed to compile script")

View File

@ -25,6 +25,7 @@ func TestLoadScriptsFrom_on_disk_js(t *testing.T) {
expectKeys := map[string]bool{
"echo-and-sleep": true,
"simple-blender-render": true,
// Should NOT contain an entry for 'empty.js'.
}
assert.Equal(t, expectKeys, keys(s.compilers))
}