@onlineapps/infrastructure-tools 1.0.44 → 1.0.46

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onlineapps/infrastructure-tools",
3
- "version": "1.0.44",
3
+ "version": "1.0.46",
4
4
  "description": "Infrastructure orchestration utilities for OA Drive infrastructure services (health tracking, queue initialization, service discovery)",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -19,7 +19,7 @@
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
21
  "@onlineapps/mq-client-core": "1.0.63",
22
- "@onlineapps/service-common": "1.0.11",
22
+ "@onlineapps/service-common": "1.0.12",
23
23
  "@onlineapps/storage-core": "1.0.9",
24
24
  "uuid": "^9.0.1",
25
25
  "@onlineapps/infra-logger": "^1.0.0"
package/src/config.js ADDED
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Runtime configuration schema for @onlineapps/infrastructure-tools.
5
+ */
6
+
7
+ const { createRuntimeConfig } = require('@onlineapps/runtime-config');
8
+ const DEFAULTS = require('./defaults');
9
+
10
+ const runtimeCfg = createRuntimeConfig({
11
+ defaults: DEFAULTS,
12
+ schema: {
13
+ infrastructureHealthQueueName: { env: 'INFRASTRUCTURE_HEALTH_QUEUE', defaultKey: 'infrastructureHealthQueueName' },
14
+ infrastructureHealthPublishIntervalMs: { env: 'INFRASTRUCTURE_HEALTH_PUBLISH_INTERVAL', defaultKey: 'infrastructureHealthPublishIntervalMs', type: 'number' },
15
+ disableHealthChecks: { env: 'DISABLE_HEALTH_CHECKS', defaultKey: 'disableHealthChecks', type: 'boolean' },
16
+ serviceName: { env: 'SERVICE_NAME', defaultKey: 'serviceName' },
17
+ }
18
+ });
19
+
20
+ module.exports = runtimeCfg;
21
+
22
+
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Module-owned defaults for @onlineapps/infrastructure-tools.
5
+ *
6
+ * IMPORTANT:
7
+ * - These defaults are for runtime behavior only (intervals/flags).
8
+ * - Infrastructure topology is not defaulted anywhere.
9
+ */
10
+
11
+ module.exports = {
12
+ infrastructureHealthQueueName: 'infrastructure.health.checks',
13
+ infrastructureHealthPublishIntervalMs: 5000,
14
+ disableHealthChecks: false,
15
+ serviceName: 'unknown-service',
16
+ };
17
+
18
+
@@ -14,6 +14,7 @@
14
14
 
15
15
  const { createLogger } = require('../utils/logger');
16
16
  const { v4: uuidv4 } = require('uuid');
17
+ const runtimeCfg = require('../config');
17
18
 
18
19
  /**
19
20
  * Create infrastructure health publisher
@@ -54,13 +55,17 @@ function createHealthPublisher(options) {
54
55
  let healthCheckInterval = null;
55
56
  let isPublishing = false;
56
57
 
57
- const queueName = config.queueName || config.infrastructureHealth?.queueName || process.env.INFRASTRUCTURE_HEALTH_QUEUE || 'infrastructure.health.checks';
58
- const publishInterval = config.publishInterval || config.infrastructureHealth?.publishInterval || parseInt(process.env.INFRASTRUCTURE_HEALTH_PUBLISH_INTERVAL) || 5000;
59
-
60
- // Support for disabling health checks via environment variable (useful for library updates)
61
- const healthChecksDisabled = process.env.DISABLE_HEALTH_CHECKS === 'true' ||
62
- process.env.DISABLE_HEALTH_CHECKS === '1' ||
63
- config.disableHealthChecks === true;
58
+ const queueName = runtimeCfg.get(
59
+ 'infrastructureHealthQueueName',
60
+ config.queueName || config.infrastructureHealth?.queueName
61
+ );
62
+ const publishInterval = runtimeCfg.get(
63
+ 'infrastructureHealthPublishIntervalMs',
64
+ config.publishInterval || config.infrastructureHealth?.publishInterval
65
+ );
66
+
67
+ const isHealthChecksDisabled = () =>
68
+ runtimeCfg.get('disableHealthChecks', config.disableHealthChecks === true);
64
69
 
65
70
  /**
66
71
  * Publish health check to infrastructure.health.checks queue
@@ -131,7 +136,7 @@ function createHealthPublisher(options) {
131
136
  }
132
137
 
133
138
  // Check if health checks are disabled (useful for library updates/maintenance)
134
- if (healthChecksDisabled) {
139
+ if (isHealthChecksDisabled()) {
135
140
  logger.warn(`[InfrastructureHealth:${serviceName}] Health checks are disabled (DISABLE_HEALTH_CHECKS=true). Skipping start.`, {
136
141
  reason: 'health_checks_disabled',
137
142
  serviceName
@@ -145,7 +150,7 @@ function createHealthPublisher(options) {
145
150
  // Then publish periodically
146
151
  healthCheckInterval = setInterval(() => {
147
152
  // Double-check disabled flag on each interval (allows runtime changes)
148
- if (healthChecksDisabled) {
153
+ if (isHealthChecksDisabled()) {
149
154
  stop();
150
155
  return;
151
156
  }
@@ -186,7 +191,7 @@ function createHealthPublisher(options) {
186
191
  stop,
187
192
  publishNow,
188
193
  isRunning: () => healthCheckInterval !== null,
189
- isDisabled: () => healthChecksDisabled
194
+ isDisabled: () => isHealthChecksDisabled()
190
195
  };
191
196
  }
192
197
 
@@ -2,6 +2,7 @@
2
2
 
3
3
  const { sendQueueMismatchAlert } = require('../monitoring/queueMismatchReporter');
4
4
  const { createLogger: createInfraLogger } = require('@onlineapps/infra-logger');
5
+ const runtimeCfg = require('../config');
5
6
 
6
7
  /**
7
8
  * initInfrastructureQueues.js
@@ -32,7 +33,7 @@ async function initInfrastructureQueues(channel, options = {}) {
32
33
 
33
34
  const logger = options.logger || console;
34
35
  const connection = options.connection || channel.connection;
35
- const serviceName = options.serviceName || process.env.SERVICE_NAME || 'unknown-service';
36
+ const serviceName = runtimeCfg.get('serviceName', options.serviceName);
36
37
  const alertOnMismatch = options.alertOnMismatch !== false;
37
38
 
38
39
  // Load queueConfig from mq-client-core
@@ -41,16 +42,20 @@ async function initInfrastructureQueues(channel, options = {}) {
41
42
  // - Business services (via conn-infra-mq connector)
42
43
  const queueConfig = options.queueConfig || require('@onlineapps/mq-client-core/src/config/queueConfig');
43
44
 
44
- const queuesToCreate = options.queues || [
45
- // Workflow infrastructure queues
46
- 'workflow.init',
47
- 'workflow.control',
48
- 'workflow.completed',
49
- 'workflow.failed',
50
- 'workflow.dlq',
51
- // Registry infrastructure queues
52
- 'registry.register',
53
- ];
45
+ const deriveInfrastructureQueueNames = (cfg) => {
46
+ const prefixes = ['workflow', 'registry', 'infrastructure', 'validation', 'monitoring', 'telemetry', 'delivery'];
47
+ const result = [];
48
+ for (const prefix of prefixes) {
49
+ const group = cfg[prefix];
50
+ if (!group || typeof group !== 'object') continue;
51
+ for (const name of Object.keys(group)) {
52
+ result.push(`${prefix}.${name}`);
53
+ }
54
+ }
55
+ return result;
56
+ };
57
+
58
+ const queuesToCreate = options.queues || deriveInfrastructureQueueNames(queueConfig);
54
59
 
55
60
  const watchChannel = (ch) => {
56
61
  if (!ch) return ch;