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 =
{
  'python' => { cmd: 'python3', ext: 'py' },
  'ruby' => { cmd: 'ruby',    ext: 'rb' },
  'node' => { cmd: 'node',    ext: 'js' },
  'php' => { cmd: 'php', ext: 'php' }
}.freeze

Instance Method Summary collapse

Instance Method Details

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



29
30
31
32
33
34
# File 'lib/trmnlp/transform_backend/subprocess.rb', line 29

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