@onlineapps/conn-orch-orchestrator 1.0.18 → 1.0.19
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 +19 -29
package/package.json
CHANGED
|
@@ -86,14 +86,14 @@ class WorkflowOrchestrator {
|
|
|
86
86
|
delivery: context?.delivery || cookbookDef?.delivery || { handler: 'none' }
|
|
87
87
|
};
|
|
88
88
|
|
|
89
|
-
// Find current step (V2: step_id
|
|
90
|
-
const step = cookbookDef.steps.find(s =>
|
|
89
|
+
// Find current step (V2: step_id only)
|
|
90
|
+
const step = cookbookDef.steps.find(s => s.step_id === current_step);
|
|
91
91
|
if (!step) {
|
|
92
92
|
throw new Error(`Step not found: ${current_step}`);
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
// Get step_id (V2)
|
|
96
|
-
const stepId = step.step_id
|
|
95
|
+
// Get step_id (V2)
|
|
96
|
+
const stepId = step.step_id;
|
|
97
97
|
|
|
98
98
|
// Check if this step is for this service
|
|
99
99
|
if (step.type === 'task' && step.service !== serviceName) {
|
|
@@ -128,28 +128,18 @@ class WorkflowOrchestrator {
|
|
|
128
128
|
|
|
129
129
|
// Update context with result - steps as OBJECT (V2 format, keyed by step_id)
|
|
130
130
|
// Each step preserves its definition (step_id, type, service, operation, input) and adds output
|
|
131
|
-
const currentIndex = cookbookDef.steps.findIndex(s =>
|
|
131
|
+
const currentIndex = cookbookDef.steps.findIndex(s => s.step_id === current_step);
|
|
132
132
|
const stepDefinition = cookbookDef.steps[currentIndex];
|
|
133
133
|
|
|
134
134
|
// Initialize steps object from cookbook if not present
|
|
135
135
|
// V2: steps is an object keyed by step_id, not an array
|
|
136
136
|
let existingSteps = enrichedContext.steps || {};
|
|
137
137
|
|
|
138
|
-
//
|
|
139
|
-
if (
|
|
140
|
-
existingSteps = {};
|
|
138
|
+
// Initialize from cookbook if empty
|
|
139
|
+
if (Object.keys(existingSteps).length === 0) {
|
|
141
140
|
cookbookDef.steps.forEach(s => {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
existingSteps[sid] = { ...s };
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
} else if (Object.keys(existingSteps).length === 0) {
|
|
148
|
-
// Initialize from cookbook
|
|
149
|
-
cookbookDef.steps.forEach(s => {
|
|
150
|
-
const sid = s.step_id || s.id;
|
|
151
|
-
if (sid) {
|
|
152
|
-
existingSteps[sid] = { ...s };
|
|
141
|
+
if (s.step_id) {
|
|
142
|
+
existingSteps[s.step_id] = { ...s };
|
|
153
143
|
}
|
|
154
144
|
});
|
|
155
145
|
}
|
|
@@ -198,7 +188,7 @@ class WorkflowOrchestrator {
|
|
|
198
188
|
|
|
199
189
|
if (nextStep) {
|
|
200
190
|
// Route to next step
|
|
201
|
-
const nextStepId = nextStep.step_id
|
|
191
|
+
const nextStepId = nextStep.step_id;
|
|
202
192
|
await this._routeToNextStep(nextStep, cookbookDef, updatedContext, workflow_id, nextStepId);
|
|
203
193
|
} else {
|
|
204
194
|
// Workflow completed - pass serviceName, cookbook and last step info for monitoring
|
|
@@ -293,13 +283,13 @@ class WorkflowOrchestrator {
|
|
|
293
283
|
|
|
294
284
|
// Use API mapper to call the service with resolved input
|
|
295
285
|
const result = await this.apiMapper.callOperation(
|
|
296
|
-
step.operation
|
|
286
|
+
step.operation,
|
|
297
287
|
resolvedInput,
|
|
298
288
|
context
|
|
299
289
|
);
|
|
300
290
|
|
|
301
291
|
this.logger.info(`Task step executed`, {
|
|
302
|
-
step: step.step_id
|
|
292
|
+
step: step.step_id,
|
|
303
293
|
service: step.service,
|
|
304
294
|
operation: step.operation,
|
|
305
295
|
inputResolved: !!resolvedInput
|
|
@@ -420,7 +410,7 @@ class WorkflowOrchestrator {
|
|
|
420
410
|
const result = await executor.executeStep(step);
|
|
421
411
|
|
|
422
412
|
this.logger.info(`Control flow step executed`, {
|
|
423
|
-
step: step.step_id
|
|
413
|
+
step: step.step_id,
|
|
424
414
|
type: step.type
|
|
425
415
|
});
|
|
426
416
|
|
|
@@ -441,7 +431,7 @@ class WorkflowOrchestrator {
|
|
|
441
431
|
const message = {
|
|
442
432
|
workflow_id,
|
|
443
433
|
cookbook: cookbookDef,
|
|
444
|
-
current_step: nextStepId
|
|
434
|
+
current_step: nextStepId,
|
|
445
435
|
context
|
|
446
436
|
};
|
|
447
437
|
|
|
@@ -450,21 +440,21 @@ class WorkflowOrchestrator {
|
|
|
450
440
|
if (this.router?.routeToService) {
|
|
451
441
|
await this.router.routeToService(nextStep.service, message);
|
|
452
442
|
this.logger.info(`Routed to service: ${nextStep.service}`, {
|
|
453
|
-
step: nextStepId
|
|
443
|
+
step: nextStepId
|
|
454
444
|
});
|
|
455
445
|
} else {
|
|
456
446
|
// Fallback: publish to service's workflow queue directly
|
|
457
447
|
const serviceQueue = `${nextStep.service}.workflow`;
|
|
458
448
|
await this.mqClient.publish(serviceQueue, message);
|
|
459
449
|
this.logger.info(`Published to queue: ${serviceQueue}`, {
|
|
460
|
-
step: nextStepId
|
|
450
|
+
step: nextStepId
|
|
461
451
|
});
|
|
462
452
|
}
|
|
463
453
|
} else {
|
|
464
454
|
// Control flow steps handled by workflow init queue
|
|
465
455
|
await this.mqClient.publish('workflow.init', message);
|
|
466
456
|
this.logger.info(`Routed control flow to workflow.init`, {
|
|
467
|
-
step: nextStepId
|
|
457
|
+
step: nextStepId
|
|
468
458
|
});
|
|
469
459
|
}
|
|
470
460
|
}
|
|
@@ -535,12 +525,12 @@ class WorkflowOrchestrator {
|
|
|
535
525
|
const crypto = require('crypto');
|
|
536
526
|
const data = JSON.stringify({
|
|
537
527
|
service: step.service,
|
|
538
|
-
operation: step.operation
|
|
528
|
+
operation: step.operation,
|
|
539
529
|
input: step.input,
|
|
540
530
|
contextInput: context.api_input
|
|
541
531
|
});
|
|
542
532
|
const hash = crypto.createHash('sha256').update(data).digest('hex');
|
|
543
|
-
return `workflow:step:${step.service}:${step.operation
|
|
533
|
+
return `workflow:step:${step.service}:${step.operation}:${hash}`;
|
|
544
534
|
}
|
|
545
535
|
|
|
546
536
|
/**
|