Documentation
¶
Overview ¶
Package worker implements the ws-worker host-side runner (main plan §4, internal/runner/worker). It is the third execution location after local and peer-http: instead of running a child process (local) or forwarding over HTTP (peer-http), it dispatches the job to a remote worker over the hub WebSocket and mirrors the worker's log frames back into the host job's stdout.log / stderr.log so /logs, /stream and list stay transparently usable.
The runner is constructed by commands.buildCore with the hub singleton; one worker-runner targets one configured worker_id (dynamic routing is WP4).
Import note: this package's import path is internal/runner/worker; callers alias it (e.g. workerrunner) to avoid clashing with internal/worker (the client side).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func JobEventDetail ¶
JobEventDetail decodes one mirrored job event's raw detail into the map the host job records, with the worker origin stamped (SUP-01 G). Exported so the adoption path (internal/core) applies exactly the same projection as the dispatched one — one mapping, two entry points (like OutcomeFrom).
func OutcomeFrom ¶
OutcomeFrom projects a worker-sent Outcome frame onto a runner.Outcome, stamping the Source as worker:<id> so the host job records WHERE it ran. It is exported because the serve-side ADOPTION path (RECOV-01 R4, internal/core) must apply exactly the same projection to a frame that arrives for a job this process did not dispatch — one mapping, two entry points. stamping Source="worker:<id>" so the host job records WHERE it ran (P4-c). A nil frame (old worker, no产出回传) yields nil so the host job outcome stays empty (回归红线). Artifacts is the raw清单 JSON the worker already serialised — passed through verbatim (大产物文件本身留 worker 侧, D6).
func ResultErr ¶
ResultErr maps a worker terminal result to a runner error (mirrors peerhttp.errFromStatus): done → nil; failed/timeout/cancelled or a non-terminal status → an error so the host job service classifies the job. The host still inspects its own ctx, so cancel/timeout stay correct. Exported for the RECOV-01 R4 adoption path (internal/core), which finishes a job from the same wire frame.
Types ¶
type Option ¶
type Option func(*Runner)
Option configures a Runner.
func WithLanguageFor ¶ added in v0.207.0
WithLanguageFor sets how the runner picks the language of the error text it hands a job (config.LanguageFor: the job's project language, else the server's).
func WithPtyRelay ¶
func WithPtyRelay(nonces nonceIssuer, relays relayPreparer) Option
WithPtyRelay injects the serve-side relay lifecycle dependencies used by interactive worker dispatches.
func WithQueueMaxWait ¶ added in v0.189.0
WithQueueMaxWait bounds how long a dispatch may wait for a free slot on a worker at its max_concurrent (gofer-y05q). Non-positive means no cap: queue until a slot frees or the job is cancelled.
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
Runner forwards a job to a worker over the hub and returns the worker's authoritative terminal result.
func (*Runner) Run ¶
Run dispatches req.Forward to the worker and returns the worker's terminal result. Lifecycle (review #2):
(a) register a per-job sink on the hub BEFORE dispatch (so the worker's first
log frame is never lost);
(b) send the dispatch frame;
(c) the hub's read loop mirrors inbound log frames into the sink (=
req.Stdout/Stderr) and delivers the terminal result;
(d) wait for the result (or ctx end);
(e) deregister the sink.