BREAKING CHANGE(daemon): Introduce persistent log storage, numeric ProcessId type, and improved process monitoring / IPC handling
This commit is contained in:
@@ -21,6 +21,8 @@ export class ProcessWrapper extends EventEmitter {
|
||||
private logger: Logger;
|
||||
private nextSeq: number = 0;
|
||||
private runId: string = '';
|
||||
private stdoutRemainder: string = '';
|
||||
private stderrRemainder: string = '';
|
||||
|
||||
constructor(options: IProcessWrapperOptions) {
|
||||
super();
|
||||
@@ -66,6 +68,11 @@ export class ProcessWrapper extends EventEmitter {
|
||||
const exitMessage = `Process exited with code ${code}, signal ${signal}`;
|
||||
this.logger.info(exitMessage);
|
||||
this.addSystemLog(exitMessage);
|
||||
|
||||
// Clear remainder buffers on exit
|
||||
this.stdoutRemainder = '';
|
||||
this.stderrRemainder = '';
|
||||
|
||||
this.emit('exit', code, signal);
|
||||
});
|
||||
|
||||
@@ -83,24 +90,57 @@ export class ProcessWrapper extends EventEmitter {
|
||||
|
||||
// Capture stdout
|
||||
if (this.process.stdout) {
|
||||
console.error(`[ProcessWrapper] Setting up stdout listener for process ${this.process.pid}`);
|
||||
this.process.stdout.on('data', (data) => {
|
||||
const lines = data.toString().split('\n');
|
||||
console.error(`[ProcessWrapper] Received stdout data from PID ${this.process?.pid}: ${data.toString().substring(0, 100)}`);
|
||||
// Add data to remainder buffer and split by newlines
|
||||
const text = this.stdoutRemainder + data.toString();
|
||||
const lines = text.split('\n');
|
||||
|
||||
// The last element might be a partial line
|
||||
this.stdoutRemainder = lines.pop() || '';
|
||||
|
||||
// Process complete lines
|
||||
for (const line of lines) {
|
||||
if (line.trim()) {
|
||||
this.addLog('stdout', line);
|
||||
}
|
||||
console.error(`[ProcessWrapper] Processing stdout line: ${line}`);
|
||||
this.logger.debug(`Captured stdout: ${line}`);
|
||||
this.addLog('stdout', line);
|
||||
}
|
||||
});
|
||||
|
||||
// Flush remainder on stream end
|
||||
this.process.stdout.on('end', () => {
|
||||
if (this.stdoutRemainder) {
|
||||
this.logger.debug(`Flushing stdout remainder: ${this.stdoutRemainder}`);
|
||||
this.addLog('stdout', this.stdoutRemainder);
|
||||
this.stdoutRemainder = '';
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.logger.warn('Process stdout is null');
|
||||
}
|
||||
|
||||
// Capture stderr
|
||||
if (this.process.stderr) {
|
||||
this.process.stderr.on('data', (data) => {
|
||||
const lines = data.toString().split('\n');
|
||||
// Add data to remainder buffer and split by newlines
|
||||
const text = this.stderrRemainder + data.toString();
|
||||
const lines = text.split('\n');
|
||||
|
||||
// The last element might be a partial line
|
||||
this.stderrRemainder = lines.pop() || '';
|
||||
|
||||
// Process complete lines
|
||||
for (const line of lines) {
|
||||
if (line.trim()) {
|
||||
this.addLog('stderr', line);
|
||||
}
|
||||
this.addLog('stderr', line);
|
||||
}
|
||||
});
|
||||
|
||||
// Flush remainder on stream end
|
||||
this.process.stderr.on('end', () => {
|
||||
if (this.stderrRemainder) {
|
||||
this.addLog('stderr', this.stderrRemainder);
|
||||
this.stderrRemainder = '';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user