@onlineapps/conn-orch-orchestrator 1.0.8 → 1.0.10

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/conn-orch-orchestrator",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "Workflow orchestration connector for OA Drive - handles message routing and workflow execution",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -91,32 +91,6 @@ class WorkflowOrchestrator {
91
91
  return { skipped: true, reason: 'wrong_service' };
92
92
  }
93
93
 
94
- // Publish workflow.progress to monitoring.workflow using unified helper
95
- const { publishToMonitoringWorkflow } = require('@onlineapps/mq-client-core').monitoring;
96
- try {
97
- const stepIndex = cookbookDef.steps.findIndex(s => s.id === current_step);
98
- console.log(`[WorkflowOrchestrator] [PROGRESS] Publishing progress for ${workflow_id}, step: ${current_step}, index: ${stepIndex}`);
99
- await publishToMonitoringWorkflow(this.mqClient, {
100
- event_type: 'progress',
101
- workflow_id: workflow_id,
102
- service_name: serviceName,
103
- step_index: stepIndex >= 0 ? stepIndex : 0,
104
- step_id: current_step,
105
- cookbook: cookbookDef,
106
- context: enrichedContext,
107
- status: 'in_progress',
108
- timestamp: new Date().toISOString()
109
- }, this.logger, { workflow_id, step_id: current_step });
110
- console.log(`[WorkflowOrchestrator] [PROGRESS] ✓ Progress published for ${workflow_id}`);
111
- } catch (monitoringError) {
112
- // Don't fail workflow if monitoring publish fails (helper already logs)
113
- console.error(`[WorkflowOrchestrator] [PROGRESS] ✗ Failed to publish progress:`, monitoringError);
114
- this.logger.warn('Failed to publish workflow.progress to monitoring', {
115
- workflow_id,
116
- error: monitoringError.message || String(monitoringError)
117
- });
118
- }
119
-
120
94
  // Check cache if available
121
95
  let result;
122
96
  if (this.cache && step.type === 'task') {
@@ -158,6 +132,32 @@ class WorkflowOrchestrator {
158
132
  steps: existingSteps
159
133
  };
160
134
 
135
+ // Publish workflow.progress AFTER execution (so we have step output)
136
+ const { publishToMonitoringWorkflow } = require('@onlineapps/mq-client-core').monitoring;
137
+ try {
138
+ console.log(`[WorkflowOrchestrator] [PROGRESS] Publishing progress for ${workflow_id}, step: ${current_step}, index: ${currentIndex}`);
139
+ await publishToMonitoringWorkflow(this.mqClient, {
140
+ event_type: 'progress',
141
+ workflow_id: workflow_id,
142
+ service_name: serviceName,
143
+ step_index: currentIndex >= 0 ? currentIndex : 0,
144
+ step_id: current_step,
145
+ cookbook: cookbookDef,
146
+ context: updatedContext, // Context WITH step output
147
+ output: result, // Step output directly
148
+ status: 'completed', // Step completed (not in_progress)
149
+ timestamp: new Date().toISOString()
150
+ }, this.logger, { workflow_id, step_id: current_step });
151
+ console.log(`[WorkflowOrchestrator] [PROGRESS] ✓ Progress published for ${workflow_id}`);
152
+ } catch (monitoringError) {
153
+ // Don't fail workflow if monitoring publish fails
154
+ console.error(`[WorkflowOrchestrator] [PROGRESS] ✗ Failed to publish progress:`, monitoringError);
155
+ this.logger.warn('Failed to publish workflow.progress to monitoring', {
156
+ workflow_id,
157
+ error: monitoringError.message || String(monitoringError)
158
+ });
159
+ }
160
+
161
161
  // Find next step (currentIndex already defined above)
162
162
  const nextStep = cookbookDef.steps[currentIndex + 1];
163
163
 
@@ -165,8 +165,8 @@ class WorkflowOrchestrator {
165
165
  // Route to next step
166
166
  await this._routeToNextStep(nextStep, cookbookDef, updatedContext, workflow_id);
167
167
  } else {
168
- // Workflow completed - pass serviceName and last step info for monitoring
169
- await this._completeWorkflow(workflow_id, updatedContext, serviceName, current_step, currentIndex);
168
+ // Workflow completed - pass serviceName, cookbook and last step info for monitoring
169
+ await this._completeWorkflow(workflow_id, updatedContext, cookbookDef, serviceName, current_step, currentIndex);
170
170
  }
171
171
 
172
172
  return {
@@ -345,7 +345,7 @@ class WorkflowOrchestrator {
345
345
  * @param {string} lastStepId - ID of the last completed step
346
346
  * @param {number} lastStepIndex - Index of the last completed step
347
347
  */
348
- async _completeWorkflow(workflow_id, finalContext, serviceName = 'unknown', lastStepId = null, lastStepIndex = 0) {
348
+ async _completeWorkflow(workflow_id, finalContext, cookbookDef = {}, serviceName = 'unknown', lastStepId = null, lastStepIndex = 0) {
349
349
  try {
350
350
  console.log(`[WorkflowOrchestrator] [PUBLISH] Preparing to publish workflow.completed for ${workflow_id}`);
351
351
  this.logger.info(`[WorkflowOrchestrator] [PUBLISH] Preparing to publish workflow.completed`, {
@@ -359,7 +359,7 @@ class WorkflowOrchestrator {
359
359
 
360
360
  // Extract delivery configuration from context (passed from Gateway)
361
361
  // Delivery Dispatcher requires: workflow_id, status, delivery (must be object, not null)
362
- const delivery = finalContext?.delivery || { handler: 'none' }; // Default to 'none' handler if not provided
362
+ const delivery = finalContext?.delivery || cookbookDef?.delivery || { handler: 'none' };
363
363
 
364
364
  // Build message in format expected by Delivery Dispatcher
365
365
  const workflowCompletedMessage = {
@@ -368,9 +368,10 @@ class WorkflowOrchestrator {
368
368
  service: serviceName, // Service that completed the workflow (for monitoring)
369
369
  step_id: lastStepId, // Last step ID for monitoring
370
370
  step_index: lastStepIndex, // Last step index for monitoring
371
+ cookbook: cookbookDef, // Full cookbook for monitoring trace
371
372
  delivery: delivery, // Delivery configuration from Gateway context (must be object)
372
373
  context: finalContext, // Full context for output resolution
373
- steps: finalContext?.steps || {}, // Steps results for output resolution
374
+ steps: finalContext?.steps || [], // Steps results (array) for output resolution
374
375
  completed_at: new Date().toISOString()
375
376
  };
376
377