PR 4 du chantier admin. Board de sante temps reel des dependances.
- POST /internal/tech-steps/heartbeat (requireInternalWorker) ->
recordWorkerHeartbeat : upsert WorkerHeartbeat (cle fixe
"tech-step-llm-worker"), lastRunAt/lastResult pour un ping "job".
Schema workerHeartbeatSchema dans packages/shared.
- services/tech-step-llm-worker : api-client.postHeartbeat (best-effort,
ne throw jamais) appele au boot (index.ts), a chaque tick et apres
chaque job (scheduler.ts, avec job/ok/counts).
- admin-monitoring.service.ts + GET /admin/monitoring (requireAdmin) :
sonde active bornee (~2 s) de Postgres (SELECT 1), l'API (uptime/RSS),
tech-step-intent-service (/health), et le worker via son heartbeat.
Statut up/degraded/down/unknown ; une sonde down ne casse ni les autres
ni l'endpoint. Seuils worker : > 8 j degraded, > 21 j down.
- MonitoringView / ServiceHealthView dans packages/shared.
- Front : MonitoringPage (grille de cartes coloree par statut, re-poll
15 s), logique pure monitoring.ts, i18n admin.monitoring.*,
AdminApiClient.getMonitoring.
- Tests : Mocha admin-monitoring.test.ts (heartbeat 401/400/upsert
job+boot ; GET /admin/monitoring 401, board 4 cibles, worker unknown
sans heartbeat puis up apres) ; Cypress monitoring.cy.ts (2 verts).
Worker mocha : 6/6 toujours verts.
- specs/backend-architecture.md : section monitoring. .gitignore :
apps/admin-web/cypress/{screenshots,videos,downloads}.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
67 lines
2.2 KiB
TypeScript
67 lines
2.2 KiB
TypeScript
import { wrapAsyncHandler } from "@batch-cooking/express-tools";
|
|
import {
|
|
auditBatchQuerySchema,
|
|
submitTrainingSuggestionsSchema,
|
|
workerBatchQuerySchema,
|
|
workerHeartbeatSchema,
|
|
} from "@batch-cooking/shared";
|
|
import { Router } from "express";
|
|
import { requireInternalWorker } from "../../middlewares/require-internal-worker.js";
|
|
import {
|
|
getAuditBatch,
|
|
getPendingCorrections,
|
|
recordWorkerHeartbeat,
|
|
submitTrainingSuggestions,
|
|
} from "./tech-step-worker.service.js";
|
|
|
|
/**
|
|
* Router mounted at `/internal/tech-steps` in app.ts — every route requires
|
|
* {@link requireInternalWorker}, never {@link requireAuth}
|
|
* (`middlewares/require-auth.ts`): this is `services/tech-step-llm-worker`
|
|
* authenticating as itself, not a user session. See that middleware's own
|
|
* doc comment for why the two are deliberately separate mechanisms.
|
|
*/
|
|
export const techStepWorkerRouter = Router();
|
|
|
|
techStepWorkerRouter.get(
|
|
"/audit-batch",
|
|
requireInternalWorker,
|
|
wrapAsyncHandler(async (req, res) => {
|
|
const input = auditBatchQuerySchema.parse(req.query);
|
|
res.status(200).json(await getAuditBatch(input.locale, input.limit));
|
|
}),
|
|
);
|
|
|
|
techStepWorkerRouter.get(
|
|
"/pending-corrections",
|
|
requireInternalWorker,
|
|
wrapAsyncHandler(async (req, res) => {
|
|
const input = workerBatchQuerySchema.parse(req.query);
|
|
res.status(200).json(await getPendingCorrections(input.limit));
|
|
}),
|
|
);
|
|
|
|
techStepWorkerRouter.post(
|
|
"/training-suggestions",
|
|
requireInternalWorker,
|
|
wrapAsyncHandler(async (req, res) => {
|
|
const input = submitTrainingSuggestionsSchema.parse(req.body);
|
|
res.status(201).json(await submitTrainingSuggestions(input));
|
|
}),
|
|
);
|
|
|
|
/**
|
|
* Liveness ping from the worker (which has no inbound HTTP surface of its
|
|
* own) — upserts its `WorkerHeartbeat` row so the admin monitoring board
|
|
* can show it as up / stale / down and surface its last job result. Sent
|
|
* on boot, on every scheduler tick, and after each job.
|
|
*/
|
|
techStepWorkerRouter.post(
|
|
"/heartbeat",
|
|
requireInternalWorker,
|
|
wrapAsyncHandler(async (req, res) => {
|
|
const input = workerHeartbeatSchema.parse(req.body);
|
|
await recordWorkerHeartbeat(input);
|
|
res.status(200).json({ ok: true });
|
|
}),
|
|
);
|