Documentation
¶
Overview ¶
Package syncworker isolates subtitle-sync computation in a supervised one-shot child process (P13). Sync is the engine's most memory-intensive work (PCM decode + alignment inside a 1 GiB no-swap container); running it in a same-binary `subflux sync-worker` child means a memory blowup is killed by the kernel OOM killer as the LARGEST-badness process — the fat child — while the server keeps serving. One job per process, versioned JSON over stdin/stdout, kill-on-cancel, concurrency-one admission.
The protocol carries the raw inputs of the two heavy strategies (reference-based and audio-based sync) and returns a wire copy of subsync.SyncResult. Both sides convert to/from the real subsync types, so the parent applies the SAME Applied()/ShouldApply() logic it always did — no duplicated decision rules on the wire.
Index ¶
Constants ¶
const ( // OpReference aligns subtitle data against an embedded reference track // (syncing.SyncAgainstReference). OpReference = "reference" // OpAudio aligns subtitle data against the audio track // (syncing.SyncFromAudio). OpAudio = "audio" )
Op names for Request.Op.
const ProtocolVersion = 1
ProtocolVersion guards the parent/child JSON contract. Parent and child are the same binary, so a mismatch can only mean the executable was replaced while a request was in flight (upgrade race); the child answers with an error response rather than guessing.
Variables ¶
This section is empty.
Functions ¶
func RunWorker ¶
RunWorker executes exactly one sync job read from stdin and writes the response to stdout. Called by the hidden `subflux sync-worker` subcommand. The exit code reflects PROTOCOL health only (0 even when the sync found nothing); the parent judges the job by the JSON response. ctx cancellation (parent kill, signal) aborts the underlying ffmpeg/alignment work.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client runs sync jobs in supervised one-shot `subflux sync-worker` child processes. It implements syncing.SyncExec, so the Syncer, the engine's audio fallback, and the manual sync handlers all route their heavy computation through it transparently.
Admission is concurrency-one (the P13 queue, subsuming the sync-semaphore side finding): a season sync of N episodes runs at most one alignment at a time, and manual jobs queue behind automatic ones. Failure is degradation, never escalation: a worker death (OOM kill, crash, timeout) is WARN-logged and reported as a no-change result — the subtitle stays unsynced, the download proceeds, the server keeps serving.
func NewClient ¶
NewClient builds the process-isolation client. It resolves the current executable once; construction fails only when the running binary's path cannot be determined (in which case the caller should fall back to in-process sync).
type Request ¶
type Request struct {
Op string `json:"op"`
VideoPath string `json:"video_path"`
SubtitlePath string `json:"subtitle_path,omitempty"`
Lang string `json:"lang,omitempty"`
Data []byte `json:"data"`
Version int `json:"version"`
MinConfidence float64 `json:"min_confidence,omitempty"`
}
Request is the parent->child job description, one per process invocation.
type Response ¶
type Response struct {
Error string `json:"error,omitempty"`
Result WireSyncResult `json:"result"`
Version int `json:"version"`
}
Response is the child->parent result envelope. Error is set for protocol or infrastructure failures; strategy-level "no sync found" is NOT an error (it travels as a MethodNone result, exactly like the in-process calls).