mirror of
https://github.com/tiennm99/ccs.git
synced 2026-09-05 18:16:28 +00:00
fix(web-server): run usage cleanup during dashboard shutdown
- pass server cleanup callback into graceful shutdown wiring - stop usage aggregator background sync when config server exits - prevent orphaned sync intervals across dashboard restarts
This commit is contained in:
@@ -160,10 +160,10 @@ export async function handleConfigCommand(args: string[]): Promise<void> {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Start server
|
// Start server
|
||||||
const { server, wss } = await startServer({ port, dev: options.dev });
|
const { server, wss, cleanup } = await startServer({ port, dev: options.dev });
|
||||||
|
|
||||||
// Setup graceful shutdown
|
// Setup graceful shutdown
|
||||||
setupGracefulShutdown(server, wss);
|
setupGracefulShutdown(server, wss, cleanup);
|
||||||
|
|
||||||
const url = `http://localhost:${port}`;
|
const url = `http://localhost:${port}`;
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import { WebSocketServer } from 'ws';
|
|||||||
import { setupWebSocket } from './websocket';
|
import { setupWebSocket } from './websocket';
|
||||||
import { createSessionMiddleware, authMiddleware } from './middleware/auth-middleware';
|
import { createSessionMiddleware, authMiddleware } from './middleware/auth-middleware';
|
||||||
import { startAutoSyncWatcher, stopAutoSyncWatcher } from '../cliproxy/sync';
|
import { startAutoSyncWatcher, stopAutoSyncWatcher } from '../cliproxy/sync';
|
||||||
|
import { shutdownUsageAggregator } from './usage/aggregator';
|
||||||
|
|
||||||
export interface ServerOptions {
|
export interface ServerOptions {
|
||||||
port: number;
|
port: number;
|
||||||
@@ -107,6 +108,7 @@ export async function startServer(options: ServerOptions): Promise<ServerInstanc
|
|||||||
const cleanup = () => {
|
const cleanup = () => {
|
||||||
wsCleanup();
|
wsCleanup();
|
||||||
stopAutoSyncWatcher().catch(() => {});
|
stopAutoSyncWatcher().catch(() => {});
|
||||||
|
shutdownUsageAggregator();
|
||||||
};
|
};
|
||||||
|
|
||||||
// Start listening
|
// Start listening
|
||||||
|
|||||||
Reference in New Issue
Block a user