import { scope } from 'go-go-scope';
async function startHealthMonitoring() {
await using s = scope();
// Poll health every 30 seconds
const monitor = s.poll(
async (signal) => {
const health = await healthCheck();
// Alert if any service is unhealthy
const unhealthy = health.filter(h => !h.healthy);
if (unhealthy.length > 0) {
await sendAlert({
level: 'warning',
services: unhealthy.map(h => h.service),
timestamp: Date.now(),
});
}
return health;
},
{ interval: 30000 }
);
// Monitor runs until scope is disposed
await monitor.start();
}