mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-17 12:22:34 +03:00
* perf(logging): offload call-log artifacts to a worker * test(call-log): raise drain wait timeout for cold worker spawn The first cold spawn of the worker_threads artifact worker can take ~2.4s before queued artifact writes start draining, so a 2s wait in call-log-save-drain.test.ts flakes on cold runs. Raise it to 10s. Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> --------- Co-authored-by: xz-dev <xz-dev@users.noreply.github.com> Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
58 lines
1.6 KiB
TypeScript
58 lines
1.6 KiB
TypeScript
import { parentPort } from "node:worker_threads";
|
|
|
|
import {
|
|
writeCallArtifact,
|
|
type CallLogArtifact,
|
|
type CallLogArtifactWriteResult,
|
|
} from "./callLogArtifacts.ts";
|
|
|
|
type WriteRequest = {
|
|
id: number;
|
|
artifact: CallLogArtifact;
|
|
environment: {
|
|
pipelineMaxSizeKb?: string;
|
|
chatDebugFile?: string;
|
|
appLogLevel?: string;
|
|
};
|
|
};
|
|
|
|
type WriteReply = {
|
|
id: number;
|
|
result: CallLogArtifactWriteResult | null;
|
|
};
|
|
|
|
function applyWriteEnvironment(environment: WriteRequest["environment"]): void {
|
|
const values = {
|
|
CALL_LOG_PIPELINE_MAX_SIZE_KB: environment.pipelineMaxSizeKb,
|
|
CHAT_DEBUG_FILE: environment.chatDebugFile,
|
|
APP_LOG_LEVEL: environment.appLogLevel,
|
|
};
|
|
for (const [name, value] of Object.entries(values)) {
|
|
if (value === undefined) delete process.env[name];
|
|
else process.env[name] = value;
|
|
}
|
|
}
|
|
|
|
parentPort?.on("message", (request: WriteRequest) => {
|
|
const originalConsoleError = console.error;
|
|
let result: CallLogArtifactWriteResult | null = null;
|
|
|
|
try {
|
|
// The writer reads these options lazily; mirror the caller's per-write environment snapshot.
|
|
applyWriteEnvironment(request.environment);
|
|
// writeCallArtifact's legacy error includes filesystem paths. Keep worker failures generic.
|
|
console.error = () => {};
|
|
result = writeCallArtifact(request.artifact);
|
|
} catch {
|
|
result = null;
|
|
} finally {
|
|
console.error = originalConsoleError;
|
|
}
|
|
|
|
try {
|
|
parentPort?.postMessage({ id: request.id, result } satisfies WriteReply);
|
|
} catch {
|
|
parentPort?.postMessage({ id: request.id, result: null } satisfies WriteReply);
|
|
}
|
|
});
|