feat(scheduler): in-process matching scheduler with audit + admin endpoints
- Add in-process scheduler service triggered by ENABLE_SCHEDULER - Record runs in new matching_runs table; throttle per-event and log stats - Add admin endpoints: POST /api/admin/events/:slug/run-now and GET /api/admin/events/:slug/matching-runs - Wire scheduler start/stop in server and add ENV flags + compose defaults - Prisma schema: add MatchingRun model and relation - Update env examples for scheduler configuration
This commit is contained in:
@@ -3,6 +3,7 @@ const http = require('http');
|
||||
const app = require('./app');
|
||||
const { testConnection, disconnect } = require('./utils/db');
|
||||
const { initializeSocket } = require('./socket');
|
||||
const scheduler = require('./services/scheduler');
|
||||
|
||||
const PORT = process.env.PORT || 3000;
|
||||
|
||||
@@ -24,6 +25,16 @@ async function startServer() {
|
||||
console.log(`Server running on port: ${PORT}`);
|
||||
console.log(`Health check: http://localhost:${PORT}/api/health`);
|
||||
console.log('=================================');
|
||||
if (process.env.ENABLE_SCHEDULER === 'true') {
|
||||
try {
|
||||
scheduler.start();
|
||||
console.log('[*] Scheduler started');
|
||||
} catch (e) {
|
||||
console.error('Failed to start scheduler:', e?.message || e);
|
||||
}
|
||||
} else {
|
||||
console.log('[*] Scheduler disabled (ENABLE_SCHEDULER != "true")');
|
||||
}
|
||||
});
|
||||
|
||||
return server;
|
||||
@@ -37,12 +48,14 @@ startServer().catch((err) => {
|
||||
// Graceful shutdown
|
||||
process.on('SIGTERM', async () => {
|
||||
console.log('SIGTERM received, shutting down gracefully...');
|
||||
try { scheduler.stop(); } catch (_) {}
|
||||
await disconnect();
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
process.on('SIGINT', async () => {
|
||||
console.log('SIGINT received, shutting down gracefully...');
|
||||
try { scheduler.stop(); } catch (_) {}
|
||||
await disconnect();
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user