@wrcb/cb-common 1.0.524 → 1.0.526

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -20,7 +20,8 @@ export interface HealthCheckConfig {
20
20
  /**
21
21
  * Política:
22
22
  * - /live → liveness: SEM dependências externas, sempre 200 se o processo está up.
23
- * - /health → readiness/startup: pode retornar 503 se dependências essenciais falharem.
23
+ * - /ready → readiness estrito: 503 se alguma dependência essencial falhar.
24
+ * - /health → readiness/startup com "janela de graça" durante o bootstrap.
24
25
  *
25
26
  * Dica: alinhe o STARTUP_GRACE_PERIOD com sua startupProbe.
26
27
  * Por padrão, 300_000 ms (5min). Configurável via HEALTH_STARTUP_GRACE_MS.
@@ -19,7 +19,8 @@ const mongoose_1 = __importDefault(require("mongoose"));
19
19
  /**
20
20
  * Política:
21
21
  * - /live → liveness: SEM dependências externas, sempre 200 se o processo está up.
22
- * - /health → readiness/startup: pode retornar 503 se dependências essenciais falharem.
22
+ * - /ready → readiness estrito: 503 se alguma dependência essencial falhar.
23
+ * - /health → readiness/startup com "janela de graça" durante o bootstrap.
23
24
  *
24
25
  * Dica: alinhe o STARTUP_GRACE_PERIOD com sua startupProbe.
25
26
  * Por padrão, 300_000 ms (5min). Configurável via HEALTH_STARTUP_GRACE_MS.
@@ -33,6 +34,32 @@ function createHealthRouter(config) {
33
34
  router.get('/live', (_req, res) => {
34
35
  res.status(200).send('OK');
35
36
  });
37
+ // Readiness estrito (sem tolerância): todas dependências devem estar OK
38
+ router.get('/ready', (_req, res) => {
39
+ const checks = {
40
+ mongodb: checkMongoDB()
41
+ };
42
+ if (config.natsWrapper) {
43
+ checks.nats = checkNATS(config.natsWrapper);
44
+ }
45
+ if (config.workers) {
46
+ checks.workers = checkWorkers(config.workers, false);
47
+ }
48
+ if (config.customChecks) {
49
+ checks.custom = checkCustom(config.customChecks);
50
+ }
51
+ const allHealthy = Object.values(checks).every(check => check && typeof check === 'object' && 'status' in check
52
+ ? check.status === 'healthy'
53
+ : true);
54
+ const payload = {
55
+ status: allHealthy ? 'ready' : 'not_ready',
56
+ timestamp: new Date().toISOString(),
57
+ service: config.serviceName,
58
+ uptime: process.uptime(),
59
+ checks
60
+ };
61
+ res.status(allHealthy ? 200 : 503).json(payload);
62
+ });
36
63
  // Readiness/Startup (com tolerância durante bootstrap)
37
64
  router.get('/health', (_req, res) => {
38
65
  const now = Date.now();
@@ -73,6 +100,7 @@ function createHealthRouter(config) {
73
100
  memory: process.memoryUsage(),
74
101
  mongodb: {
75
102
  readyState: mongoose_1.default.connection.readyState,
103
+ // @ts-ignore - propriedades internas
76
104
  host: mongoose_1.default.connection.host,
77
105
  name: mongoose_1.default.connection.name
78
106
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wrcb/cb-common",
3
- "version": "1.0.524",
3
+ "version": "1.0.526",
4
4
  "description": "Common resources between services",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",