SPB Git

Repository Public

healthcheck-worker.mjs 2.2 KB 55 lines javascript

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : Sheet8 * File             : infra/healthcheck-worker.mjs9 * Module           : infra10 * Repository       : https://git.spboucher.ai/sheet11 * Project Website  : https://sheet.spboucher.ai12 * Created          : 2026-11-1713 * Last Modified    : 2026-11-1714 *15 * Author           : Simon-Pierre Boucher16 * Position         : Professor of Finance17 * Institution      : Université du Québec en Outaouais (UQO)18 * Organization     : SP Boucher19 * Website          : https://spboucher.ai20 * Git              : https://git.spboucher.ai21 *22 * Preferred Contact: contact@spboucher.ai23 * Development      : dev@spboucher.ai24 * Support          : support@spboucher.ai25 * Security/Admin   : admin@spboucher.ai26 *27 * Copyright (c) 202628 * Simon-Pierre Boucher29 * All rights reserved where applicable. This file is governed by the30 * applicable project license, copyright notices and relevant law.31 * Existing third-party rights and notices remain unaffected.32 *33 * License          : None specified (no license file in this repository)34 *35 * Do not embed credentials, private keys, access tokens,36 * certificates or confidential personal information.37 *38 * =============================================================================39 * END OF SP BOUCHER SOURCE HEADER40 * =============================================================================41 */4243// Container health check of the worker: the heartbeat row (written every 15 s by src/worker/index.ts) must be44// recent. Exit 0 = healthy, 1 = not. Used by infra/docker-compose.yml; not part of the application.45import postgres from "postgres";4647const sql = postgres(process.env.DATABASE_URL, { max: 1, connect_timeout: 5, onnotice: () => {} });48try {49  const [row] = await sql`SELECT extract(epoch FROM now() - beat_at) AS age FROM worker_heartbeat WHERE name = 'worker'`;50  await sql.end({ timeout: 2 });51  process.exit(row && Number(row.age) < 60 ? 0 : 1);52} catch {53  process.exit(1);54}55
Files main
Menu

Theme