worker

package
v0.177.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func JobEventDetail(ev wsproto.JobEvent, workerID string) map[string]any

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

func OutcomeFrom(o *wsproto.Outcome, workerID string) *runner.Outcome

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

func ResultErr(res wsproto.Result) error

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 WithPtyRelay

func WithPtyRelay(nonces nonceIssuer, relays relayPreparer) Option

WithPtyRelay injects the serve-side relay lifecycle dependencies used by interactive worker dispatches.

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 New

func New(name, workerID string, hub *wshub.Hub, opts ...Option) *Runner

New builds a worker runner named name that dispatches to workerID via hub.

func (*Runner) Name

func (r *Runner) Name() string

Name implements runner.Runner.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context, req runner.Request) runner.Result

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL