feat(core): Introduce ProcessMonitor with memory management and spawning features

This commit is contained in:
2025-03-01 18:02:40 +00:00
parent 36eb1a79a7
commit ad2c180cfe
9 changed files with 140 additions and 34 deletions

View File

@ -6,3 +6,22 @@ tap.test('first test', async () => {
});
tap.start();
// Example usage:
const config: IMonitorConfig = {
name: 'Project XYZ Monitor', // Identifier for the instance
projectDir: '/path/to/your/project', // Set the project directory here
command: 'npm run xyz', // Full command string (no need for args)
memoryLimitBytes: 500 * 1024 * 1024, // 500 MB memory limit
monitorIntervalMs: 5000, // Check memory usage every 5 seconds
};
const monitor = new ProcessMonitor(config);
monitor.start();
// Ensure that on process exit (e.g. Ctrl+C) we clean up the child process and prevent respawns.
process.on('SIGINT', () => {
monitor.log('Received SIGINT, stopping monitor...');
monitor.stop();
process.exit();
});