more stuff
This commit is contained in:
parent
c3cb36c8d6
commit
7dec0be3b4
26 changed files with 1394 additions and 275 deletions
|
|
@ -4,6 +4,7 @@ import { getLogger } from '@stock-bot/logger';
|
|||
import { initializeStockConfig } from '@stock-bot/stock-config';
|
||||
import { createRoutes } from './routes/create-routes';
|
||||
import { createWebSocketRoute, handleWebSocketConnection } from './routes/websocket.routes';
|
||||
import { BacktestDispatcher } from './services/BacktestDispatcher';
|
||||
import { getWebSocketHandler, type RunSocketData } from './websocket/run-updates';
|
||||
|
||||
// Initialize configuration with service-specific overrides
|
||||
|
|
@ -65,6 +66,15 @@ export async function startServerWithWebSocket() {
|
|||
const diContainer = await createContainer(config);
|
||||
container = diContainer.resolve('serviceContainer');
|
||||
|
||||
if (!container.postgres || !container.queueManager) {
|
||||
throw new Error('Durable backtest dispatch requires PostgreSQL and Redis queues');
|
||||
}
|
||||
const dispatcher = new BacktestDispatcher(
|
||||
container.postgres,
|
||||
container.queueManager.getQueue('{orchestrator_orchestrator}', { workers: 0 }),
|
||||
logger
|
||||
);
|
||||
|
||||
// Create HTTP routes
|
||||
const routes = createRoutes(container, security);
|
||||
|
||||
|
|
@ -125,15 +135,29 @@ export async function startServerWithWebSocket() {
|
|||
}
|
||||
|
||||
logger.info(`Web API service with WebSocket support started on port ${server.port}`);
|
||||
dispatcher.start();
|
||||
logger.info(`WebSocket endpoint available at ws://localhost:${server.port}/ws`);
|
||||
|
||||
// Handle shutdown
|
||||
process.on('SIGINT', async () => {
|
||||
let shuttingDown = false;
|
||||
const shutdown = async () => {
|
||||
if (shuttingDown) {
|
||||
return;
|
||||
}
|
||||
shuttingDown = true;
|
||||
logger.info('Shutting down server...');
|
||||
const deadline = setTimeout(() => process.exit(1), 10_000);
|
||||
deadline.unref();
|
||||
await dispatcher.shutdown();
|
||||
getWebSocketHandler()?.cleanup();
|
||||
await server.stop(true);
|
||||
await container?.queueManager?.shutdown();
|
||||
await diContainer.dispose();
|
||||
clearTimeout(deadline);
|
||||
process.exit(0);
|
||||
});
|
||||
};
|
||||
process.on('SIGINT', () => void shutdown());
|
||||
process.on('SIGTERM', () => void shutdown());
|
||||
} catch (error) {
|
||||
logger.fatal('Failed to start web API service', { error });
|
||||
process.exit(1);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue