feat(daemon): Add central TSPM daemon and IPC client; refactor CLI to use daemon and improve monitoring/error handling
This commit is contained in:
24
test/test.ts
24
test/test.ts
@@ -1,4 +1,4 @@
|
||||
import { expect, expectAsync, tap } from '@push.rocks/tapbundle';
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import * as tspm from '../ts/index.js';
|
||||
import { join } from 'path';
|
||||
|
||||
@@ -20,10 +20,10 @@ tap.test('ProcessMonitor test', async () => {
|
||||
};
|
||||
|
||||
const monitor = new tspm.ProcessMonitor(config);
|
||||
|
||||
|
||||
// Test monitor creation
|
||||
expect(monitor).toBeInstanceOf(tspm.ProcessMonitor);
|
||||
|
||||
|
||||
// We won't actually start it in tests to avoid side effects
|
||||
// but we can test the API
|
||||
expect(monitor.start).toBeInstanceOf('function');
|
||||
@@ -34,7 +34,7 @@ tap.test('ProcessMonitor test', async () => {
|
||||
// Tspm class test
|
||||
tap.test('Tspm class test', async () => {
|
||||
const tspmInstance = new tspm.Tspm();
|
||||
|
||||
|
||||
expect(tspmInstance).toBeInstanceOf(tspm.Tspm);
|
||||
expect(tspmInstance.start).toBeInstanceOf('function');
|
||||
expect(tspmInstance.stop).toBeInstanceOf('function');
|
||||
@@ -70,7 +70,7 @@ function exampleUsingProcessMonitor() {
|
||||
monitor.stop();
|
||||
process.exit();
|
||||
});
|
||||
|
||||
|
||||
// Get logs example
|
||||
setTimeout(() => {
|
||||
const logs = monitor.getLogs(10); // Get last 10 log lines
|
||||
@@ -81,7 +81,7 @@ function exampleUsingProcessMonitor() {
|
||||
// Example 2: Using Tspm (higher-level process manager)
|
||||
async function exampleUsingTspm() {
|
||||
const tspmInstance = new tspm.Tspm();
|
||||
|
||||
|
||||
// Start a process
|
||||
await tspmInstance.start({
|
||||
id: 'web-server',
|
||||
@@ -93,7 +93,7 @@ async function exampleUsingTspm() {
|
||||
watch: true,
|
||||
monitorIntervalMs: 10000,
|
||||
});
|
||||
|
||||
|
||||
// Start another process
|
||||
await tspmInstance.start({
|
||||
id: 'api-server',
|
||||
@@ -103,22 +103,22 @@ async function exampleUsingTspm() {
|
||||
memoryLimitBytes: 400 * 1024 * 1024, // 400 MB
|
||||
autorestart: true,
|
||||
});
|
||||
|
||||
|
||||
// List all processes
|
||||
const processes = tspmInstance.list();
|
||||
console.log('Running processes:', processes);
|
||||
|
||||
|
||||
// Get logs from a process
|
||||
const logs = tspmInstance.getLogs('web-server', 20);
|
||||
console.log('Web server logs:', logs);
|
||||
|
||||
|
||||
// Stop a process
|
||||
await tspmInstance.stop('api-server');
|
||||
|
||||
|
||||
// Handle graceful shutdown
|
||||
process.on('SIGINT', async () => {
|
||||
console.log('Shutting down all processes...');
|
||||
await tspmInstance.stopAll();
|
||||
process.exit();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user