feat(F-054): completed feature
This commit is contained in:
@@ -4,6 +4,18 @@ import { createPool } from '../db/pool.js';
|
||||
import { createFlagStore } from '../../modules/flags/index.js';
|
||||
import { createLogger } from '../logging/logger.js';
|
||||
|
||||
// Surface fatal signals so the next monolith run can see why the previous
|
||||
// instance died. Without these, SIGTERM/SIGKILL from a harness or the OS
|
||||
// leaves no trace in the runtime log.
|
||||
process.on('uncaughtException', (err) => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('uncaughtException', err);
|
||||
});
|
||||
process.on('unhandledRejection', (reason) => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('unhandledRejection', reason);
|
||||
});
|
||||
|
||||
let config;
|
||||
try {
|
||||
config = loadConfig(process.env);
|
||||
@@ -29,6 +41,13 @@ try {
|
||||
});
|
||||
await app.listen({ port: config.port, host: config.host });
|
||||
logger.info({ port: config.port, host: config.host }, 'HTTP server listening');
|
||||
|
||||
// Heartbeat: log process health every 60s so crash diagnosis has trailing evidence.
|
||||
const startTime = Date.now();
|
||||
setInterval(() => {
|
||||
const uptimeSec = Math.floor((Date.now() - startTime) / 1000);
|
||||
logger.info({ uptimeSec, memMB: Math.round(process.memoryUsage().heapUsed / 1024 / 1024) }, 'heartbeat');
|
||||
}, 60_000).unref();
|
||||
} catch (error) {
|
||||
logger.error({ err: error }, 'Failed to start HTTP server');
|
||||
await pool.end();
|
||||
|
||||
Reference in New Issue
Block a user