@onlineapps/conn-orch-orchestrator 1.0.5 → 1.0.7
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 +1 -1
- package/src/WorkflowOrchestrator.js +29 -10
package/package.json
CHANGED
|
@@ -135,25 +135,38 @@ class WorkflowOrchestrator {
|
|
|
135
135
|
result = await this._executeStep(step, enrichedContext, cookbookDef);
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
// Update context with result (
|
|
138
|
+
// Update context with result - steps as ARRAY (consistent with cookbook.steps)
|
|
139
|
+
// Each step preserves its definition (id, type, service, operation, input) and adds output
|
|
140
|
+
const currentIndex = cookbookDef.steps.findIndex(s => s.id === current_step);
|
|
141
|
+
const stepDefinition = cookbookDef.steps[currentIndex];
|
|
142
|
+
|
|
143
|
+
// Initialize steps array from cookbook if not present
|
|
144
|
+
const existingSteps = Array.isArray(enrichedContext.steps)
|
|
145
|
+
? [...enrichedContext.steps]
|
|
146
|
+
: cookbookDef.steps.map(s => ({ ...s })); // Deep copy of step definitions
|
|
147
|
+
|
|
148
|
+
// Update the current step with output (preserve id, type, service, operation, input)
|
|
149
|
+
existingSteps[currentIndex] = {
|
|
150
|
+
...stepDefinition, // id, type, service, operation, input
|
|
151
|
+
output: result, // Add output from operation
|
|
152
|
+
status: 'completed',
|
|
153
|
+
completed_at: new Date().toISOString()
|
|
154
|
+
};
|
|
155
|
+
|
|
139
156
|
const updatedContext = {
|
|
140
157
|
...enrichedContext,
|
|
141
|
-
steps:
|
|
142
|
-
...enrichedContext.steps,
|
|
143
|
-
[current_step]: result
|
|
144
|
-
}
|
|
158
|
+
steps: existingSteps
|
|
145
159
|
};
|
|
146
160
|
|
|
147
|
-
// Find next step
|
|
148
|
-
const currentIndex = cookbookDef.steps.findIndex(s => s.id === current_step);
|
|
161
|
+
// Find next step (currentIndex already defined above)
|
|
149
162
|
const nextStep = cookbookDef.steps[currentIndex + 1];
|
|
150
163
|
|
|
151
164
|
if (nextStep) {
|
|
152
165
|
// Route to next step
|
|
153
166
|
await this._routeToNextStep(nextStep, cookbookDef, updatedContext, workflow_id);
|
|
154
167
|
} else {
|
|
155
|
-
// Workflow completed - pass serviceName for monitoring
|
|
156
|
-
await this._completeWorkflow(workflow_id, updatedContext, serviceName);
|
|
168
|
+
// Workflow completed - pass serviceName and last step info for monitoring
|
|
169
|
+
await this._completeWorkflow(workflow_id, updatedContext, serviceName, current_step, currentIndex);
|
|
157
170
|
}
|
|
158
171
|
|
|
159
172
|
return {
|
|
@@ -329,13 +342,17 @@ class WorkflowOrchestrator {
|
|
|
329
342
|
* @param {string} workflow_id - Workflow ID
|
|
330
343
|
* @param {Object} finalContext - Final workflow context
|
|
331
344
|
* @param {string} serviceName - Service name that completed the workflow
|
|
345
|
+
* @param {string} lastStepId - ID of the last completed step
|
|
346
|
+
* @param {number} lastStepIndex - Index of the last completed step
|
|
332
347
|
*/
|
|
333
|
-
async _completeWorkflow(workflow_id, finalContext, serviceName = 'unknown') {
|
|
348
|
+
async _completeWorkflow(workflow_id, finalContext, serviceName = 'unknown', lastStepId = null, lastStepIndex = 0) {
|
|
334
349
|
try {
|
|
335
350
|
console.log(`[WorkflowOrchestrator] [PUBLISH] Preparing to publish workflow.completed for ${workflow_id}`);
|
|
336
351
|
this.logger.info(`[WorkflowOrchestrator] [PUBLISH] Preparing to publish workflow.completed`, {
|
|
337
352
|
workflow_id,
|
|
338
353
|
serviceName,
|
|
354
|
+
lastStepId,
|
|
355
|
+
lastStepIndex,
|
|
339
356
|
hasMqClient: !!this.mqClient,
|
|
340
357
|
mqClientConnected: this.mqClient?._connected
|
|
341
358
|
});
|
|
@@ -349,6 +366,8 @@ class WorkflowOrchestrator {
|
|
|
349
366
|
workflow_id,
|
|
350
367
|
status: 'completed',
|
|
351
368
|
service: serviceName, // Service that completed the workflow (for monitoring)
|
|
369
|
+
step_id: lastStepId, // Last step ID for monitoring
|
|
370
|
+
step_index: lastStepIndex, // Last step index for monitoring
|
|
352
371
|
delivery: delivery, // Delivery configuration from Gateway context (must be object)
|
|
353
372
|
context: finalContext, // Full context for output resolution
|
|
354
373
|
steps: finalContext?.steps || {}, // Steps results for output resolution
|