* Register health endpoint
(app: FastifyInstance)
| 450 | * Register health endpoint |
| 451 | */ |
| 452 | function registerHealthEndpoint(app: FastifyInstance) { |
| 453 | app.get('/health', async (_, reply) => { |
| 454 | // Check if worker is shutting down |
| 455 | if (ApiConfig.isWorkerNode()) { |
| 456 | const executor = getExecutor() as WorkerExecutor; |
| 457 | if (executor.isShuttingDown) { |
| 458 | return reply.status(503).send({ status: 'shutting_down' }); |
| 459 | } |
| 460 | } |
| 461 | try { |
| 462 | await db.countAsync({}); |
| 463 | return { status: 'ok' }; |
| 464 | } catch (_) { |
| 465 | return reply.status(503).send({ status: 'database_unreachable' }); |
| 466 | } |
| 467 | }); |
| 468 | } |
| 469 | |
| 470 | export function buildApp( |
| 471 | scrapers: any[], |
no test coverage detected