refactor(worker): split god-handler into per-message type files
Extract handleWorkerMessage (380 lines, 12 positional args) into dispatcher + focused handler modules. Dispatcher now routes by message.type to run-log / run-status / run-finished handlers, each receiving (event, deps, context) triple. run-finished is further decomposed into 5 steps: finalizeRun, accumulateAndRotateSession, emitAndNotifyCompletion, runPostCompletionAutomation, triggerSelfWake. No behavior change: all branches, notifications, lease renewals, circuit breaker, and escalation semantics preserved. Schema validation stays at dispatcher top level.
This commit is contained in:
1 parent
69724f0188
commit
cc02b45864
7 files changed
+515
-336
No files matched your search
@@ -0,0 +1,22 @@
|
||||
import {
|
||||
accumulateAndRotateSession,
|
||||
emitAndNotifyCompletion,
|
||||
finalizeRun,
|
||||
runPostCompletionAutomation,
|
||||
triggerSelfWake,
|
||||
} from "./run-finished-helpers";
|
||||
import type { HandlerContext, HandlerDeps, WorkerMessageEvent } from "./handler-context";
|
||||
|
||||
export function handleRunFinished(
|
||||
event: Extract<WorkerMessageEvent, { type: "run-finished" }>,
|
||||
deps: HandlerDeps,
|
||||
context: HandlerContext,
|
||||
): void {
|
||||
const rfCtx = finalizeRun(event, deps, context);
|
||||
if (!rfCtx) return;
|
||||
|
||||
accumulateAndRotateSession(event, deps, rfCtx);
|
||||
emitAndNotifyCompletion(event, deps, rfCtx);
|
||||
const { hadDeferredWakes } = runPostCompletionAutomation(event, deps, context, rfCtx);
|
||||
triggerSelfWake(event, deps, context, rfCtx, hadDeferredWakes);
|
||||
}
|
||||
Reference in new issue
Block a user