@onlineapps/service-wrapper 2.0.50 → 2.0.51

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/service-wrapper",
3
- "version": "2.0.50",
3
+ "version": "2.0.51",
4
4
  "description": "Thin orchestration layer for microservices - delegates all infrastructure concerns to specialized connectors",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -562,6 +562,57 @@ class ServiceWrapper {
562
562
  }
563
563
  }
564
564
 
565
+ /**
566
+ * Run health check before workflow step (debug mode only)
567
+ * @private
568
+ * @param {Object} message - Workflow message
569
+ */
570
+ async _runHealthCheckBeforeWorkflowStep(message) {
571
+ if (!this.mqClient || !this.mqClient._transport) {
572
+ return;
573
+ }
574
+
575
+ const transport = this.mqClient._transport;
576
+
577
+ // Check if transport has performHealthCheck method (public API)
578
+ if (typeof transport.performHealthCheck === 'function') {
579
+ try {
580
+ const health = await transport.performHealthCheck();
581
+
582
+ this.logger?.debug('[ServiceWrapper] [DEBUG] Health check before workflow step', {
583
+ workflow_id: message.workflow_id || message.workflowId,
584
+ current_step: message.current_step,
585
+ health: {
586
+ healthy: health.healthy,
587
+ issues: health.issues,
588
+ consumers: {
589
+ active: health.consumers.active,
590
+ tracked: health.consumers.tracked
591
+ },
592
+ queues: {
593
+ checked: health.queues.checked,
594
+ missing: health.queues.missing,
595
+ noConsumer: health.queues.noConsumer
596
+ },
597
+ channels: health.channels
598
+ }
599
+ });
600
+
601
+ if (!health.healthy) {
602
+ this.logger?.warn('[ServiceWrapper] [DEBUG] Health check FAILED before workflow step', {
603
+ workflow_id: message.workflow_id || message.workflowId,
604
+ issues: health.issues
605
+ });
606
+ }
607
+ } catch (err) {
608
+ this.logger?.warn('[ServiceWrapper] [DEBUG] Health check error before workflow step', {
609
+ error: err.message,
610
+ workflow_id: message.workflow_id || message.workflowId
611
+ });
612
+ }
613
+ }
614
+ }
615
+
565
616
  /**
566
617
  * Register MQ channel close hooks and health monitoring
567
618
  * Must be called AFTER monitoring is initialized
@@ -637,9 +688,10 @@ class ServiceWrapper {
637
688
  const serviceName = this.config.service?.name || 'unnamed-service';
638
689
 
639
690
  // Health monitoring and channel close hooks configuration
691
+ // NOTE: Health monitoring is NOT run periodically - it's triggered manually before workflow steps in debug mode
640
692
  const healthCheckConfig = {
641
- healthCheckInterval: this.config.wrapper?.mq?.healthCheckInterval || 30000, // 30s
642
- healthCheckEnabled: this.config.wrapper?.mq?.healthCheckEnabled !== false, // Default: true
693
+ healthCheckInterval: this.config.wrapper?.mq?.healthCheckInterval || 30000, // Not used when healthCheckEnabled=false
694
+ healthCheckEnabled: false, // Disable periodic checks - we'll run manually before workflow steps
643
695
  criticalHealthShutdown: this.config.wrapper?.mq?.criticalHealthShutdown !== false, // Default: true
644
696
  criticalHealthShutdownDelay: this.config.wrapper?.mq?.criticalHealthShutdownDelay || 60000, // 60s
645
697
  // Health reporting callbacks
@@ -1197,6 +1249,11 @@ class ServiceWrapper {
1197
1249
  throw new Error('Workflow message must have current_step field or cookbook with at least one step');
1198
1250
  }
1199
1251
 
1252
+ // DEBUG MODE: Run health check before workflow step
1253
+ if (process.env.DEBUG === 'true' || process.env.NODE_ENV === 'development') {
1254
+ await this._runHealthCheckBeforeWorkflowStep(message);
1255
+ }
1256
+
1200
1257
  // Normalize message format: Gateway sends workflowId, orchestrator expects workflow_id
1201
1258
  const normalizedMessage = {
1202
1259
  ...message,