Class: TRMNLP::TransformBackend::Subprocess

Inherits:
Object
  • Object
show all
Defined in:
lib/trmnlp/transform_backend/subprocess.rb

Overview

Local subprocess execution of user transform code. Mirrors the remote-daemon wrapper contract so a transform behaves the same locally as it does in production. Output flows back via a tempfile per-execution instead of FD 3, but the run/result/input dispatch logic is preserved verbatim via the shared Wrapper module.

Constant Summary collapse

DEFAULT_TIMEOUT =
30
GRACE_PERIOD =

Seconds a TERM'd process is given to exit before escalating to KILL.

0.1
INTERPRETERS =

Candidate commands per language, highest priority first. Windows is why a language needs more than one: its python.org installer provides python and the py launcher but no python3. py ranks last yet is the surest Windows hit — it stays on PATH even when the installer's optional "Add to PATH" step is skipped.

{
  'python' => { cmds: %w[python3 python py], ext: 'py' },
  'ruby' => { cmds: %w[ruby],                ext: 'rb' },
  'node' => { cmds: %w[node],                ext: 'js' },
  'php' => { cmds: %w[php],                  ext: 'php' }
}.freeze

Instance Method Summary collapse

Instance Method Details

#execute(code:, language:, stdin: '', timeout_seconds: DEFAULT_TIMEOUT) ⇒ Object



35
36
37
38
39
40
# File 'lib/trmnlp/transform_backend/subprocess.rb', line 35

def execute(code:, language:, stdin: '', timeout_seconds: DEFAULT_TIMEOUT)
  spec = INTERPRETERS[language.to_s]
  return failure("unsupported language: #{language}") unless spec

  invoke(spec, language.to_s, code, stdin, timeout_seconds)
end