Class: TRMNLP::TransformBackend::Http
- Inherits:
-
Object
- Object
- TRMNLP::TransformBackend::Http
- Defined in:
- lib/trmnlp/transform_backend/http.rb
Overview
Remote-daemon transform execution. Speaks the production daemon’s wire format over HTTP so trmnlp can target a real remote transform daemon (or any compatible server) instead of running transforms locally. Selected by TransformClient.from_config when serverless_daemon_url is set in the project’s .trmnlp.yml.
The daemon expects code that already includes its own harness (reading stdin, dispatching to run/transform/result, writing the canonical JSON result to FD 3). The shared Wrapper module emits the same harness Subprocess uses, parameterized on a FD-3 sink so a transform behaves identically whether previewed against the daemon or run locally.
Constant Summary collapse
- SUPPORTED_LANGUAGES =
%w[python ruby php node].freeze
- DEFAULT_TIMEOUT =
30- HTTP_TIMEOUT =
60
Instance Method Summary collapse
- #execute(code:, language:, stdin: '', timeout_seconds: DEFAULT_TIMEOUT) ⇒ Object
-
#initialize(url:, api_key: nil, http_timeout: HTTP_TIMEOUT) ⇒ Http
constructor
A new instance of Http.
Constructor Details
#initialize(url:, api_key: nil, http_timeout: HTTP_TIMEOUT) ⇒ Http
Returns a new instance of Http.
28 29 30 31 32 |
# File 'lib/trmnlp/transform_backend/http.rb', line 28 def initialize(url:, api_key: nil, http_timeout: HTTP_TIMEOUT) @url = url @api_key = api_key @http_timeout = http_timeout end |
Instance Method Details
#execute(code:, language:, stdin: '', timeout_seconds: DEFAULT_TIMEOUT) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/trmnlp/transform_backend/http.rb', line 34 def execute(code:, language:, stdin: '', timeout_seconds: DEFAULT_TIMEOUT) lang = language.to_s return failure("unsupported serverless_language: #{lang}") unless SUPPORTED_LANGUAGES.include?(lang) post(code: Wrapper.for(lang, code, sink_for(lang)), stdin:, timeout: timeout_seconds, language: lang) end |