Debug splitting normal and metrics tables
This commit is contained in:
@@ -18,6 +18,7 @@ const updateClients = new Set();
|
||||
const importClients = new Set();
|
||||
const resetClients = new Set();
|
||||
const resetMetricsClients = new Set();
|
||||
const calculateMetricsClients = new Set();
|
||||
|
||||
// Helper to send progress to specific clients
|
||||
function sendProgressToClients(clients, progress) {
|
||||
@@ -130,6 +131,28 @@ router.get('/reset-metrics/progress', (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
// Add calculate-metrics progress endpoint
|
||||
router.get('/calculate-metrics/progress', (req, res) => {
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'text/event-stream',
|
||||
'Cache-Control': 'no-cache',
|
||||
'Connection': 'keep-alive',
|
||||
'Access-Control-Allow-Origin': req.headers.origin || '*',
|
||||
'Access-Control-Allow-Credentials': 'true'
|
||||
});
|
||||
|
||||
// Send an initial message to test the connection
|
||||
res.write('data: {"status":"running","operation":"Initializing connection..."}\n\n');
|
||||
|
||||
// Add this client to the calculate-metrics set
|
||||
calculateMetricsClients.add(res);
|
||||
|
||||
// Remove client when connection closes
|
||||
req.on('close', () => {
|
||||
calculateMetricsClients.delete(res);
|
||||
});
|
||||
});
|
||||
|
||||
// Debug endpoint to verify route registration
|
||||
router.get('/test', (req, res) => {
|
||||
console.log('CSV test endpoint hit');
|
||||
@@ -525,7 +548,7 @@ router.post('/calculate-metrics', async (req, res) => {
|
||||
res.status(200).json({ message: 'Metrics calculation started' });
|
||||
|
||||
// Send initial progress through SSE
|
||||
sendProgressToClients(importClients, {
|
||||
sendProgressToClients(calculateMetricsClients, {
|
||||
status: 'running',
|
||||
operation: 'Starting metrics calculation',
|
||||
percentage: '0'
|
||||
@@ -536,7 +559,7 @@ router.post('/calculate-metrics', async (req, res) => {
|
||||
await calculateMetrics();
|
||||
|
||||
// Send completion through SSE
|
||||
sendProgressToClients(importClients, {
|
||||
sendProgressToClients(calculateMetricsClients, {
|
||||
status: 'complete',
|
||||
operation: 'Metrics calculation completed',
|
||||
percentage: '100'
|
||||
@@ -547,7 +570,7 @@ router.post('/calculate-metrics', async (req, res) => {
|
||||
console.error('Error during metrics calculation:', error);
|
||||
|
||||
// Send error through SSE
|
||||
sendProgressToClients(importClients, {
|
||||
sendProgressToClients(calculateMetricsClients, {
|
||||
status: 'error',
|
||||
error: error.message || 'Failed to calculate metrics'
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user