mirror of
https://github.com/whyour/qinglong.git
synced 2026-09-22 02:27:44 +08:00
feat(ql3): establish 3.0 incubation baseline
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import type { ChildProcess } from 'child_process';
|
||||
import type { LegacyExecutionObservation } from '../ports/legacyExecutionObserver';
|
||||
|
||||
export interface LegacyProcessObservationOptions {
|
||||
now?: () => number;
|
||||
logArtifactId?: string;
|
||||
}
|
||||
|
||||
export function observeLegacyChildProcess(
|
||||
child: ChildProcess,
|
||||
observation: LegacyExecutionObservation,
|
||||
options: LegacyProcessObservationOptions = {},
|
||||
): void {
|
||||
const now = options.now ?? Date.now;
|
||||
child.once('spawn', () => {
|
||||
const atMs = now();
|
||||
observation.spawned({
|
||||
atMs,
|
||||
...(child.pid === undefined ? {} : { pid: child.pid }),
|
||||
...(child.pid === undefined
|
||||
? {}
|
||||
: { executorHandle: `legacy-local:${child.pid}` }),
|
||||
...(options.logArtifactId === undefined
|
||||
? {}
|
||||
: { logArtifactId: options.logArtifactId }),
|
||||
});
|
||||
observation.running({ atMs });
|
||||
});
|
||||
child.on('error', () => {
|
||||
observation.startFailed({
|
||||
atMs: now(),
|
||||
errorCode: 'LEGACY_PROCESS_ERROR',
|
||||
});
|
||||
});
|
||||
child.once('exit', (exitCode, signal) => {
|
||||
observation.exited({
|
||||
atMs: now(),
|
||||
exitCode,
|
||||
...(signal === null ? {} : { signal }),
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user