@emmvish/stable-request 2.8.4 → 3.0.0
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/LICENSE +1 -1
- package/README.md +1153 -2319
- package/dist/constants/index.d.ts +0 -10
- package/dist/constants/index.d.ts.map +1 -1
- package/dist/constants/index.js +0 -113
- package/dist/constants/index.js.map +1 -1
- package/dist/core/index.d.ts +0 -5
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +0 -5
- package/dist/core/index.js.map +1 -1
- package/dist/core/stable-request.d.ts.map +1 -1
- package/dist/core/stable-request.js +22 -7
- package/dist/core/stable-request.js.map +1 -1
- package/dist/enums/index.d.ts +0 -37
- package/dist/enums/index.d.ts.map +1 -1
- package/dist/enums/index.js +0 -43
- package/dist/enums/index.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -3
- package/dist/index.js.map +1 -1
- package/dist/types/index.d.ts +100 -1135
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utilities/index.d.ts +0 -18
- package/dist/utilities/index.d.ts.map +1 -1
- package/dist/utilities/index.js +0 -18
- package/dist/utilities/index.js.map +1 -1
- package/dist/utilities/infrastructure-persistence.d.ts +0 -1
- package/dist/utilities/infrastructure-persistence.d.ts.map +1 -1
- package/dist/utilities/infrastructure-persistence.js +12 -15
- package/dist/utilities/infrastructure-persistence.js.map +1 -1
- package/dist/utilities/metrics-aggregator.d.ts +2 -13
- package/dist/utilities/metrics-aggregator.d.ts.map +1 -1
- package/dist/utilities/metrics-aggregator.js +9 -251
- package/dist/utilities/metrics-aggregator.js.map +1 -1
- package/dist/utilities/metrics-validator.d.ts +6 -76
- package/dist/utilities/metrics-validator.d.ts.map +1 -1
- package/dist/utilities/metrics-validator.js +12 -181
- package/dist/utilities/metrics-validator.js.map +1 -1
- package/dist/utilities/validate-trial-mode-probabilities.js +2 -2
- package/dist/utilities/validate-trial-mode-probabilities.js.map +1 -1
- package/package.json +20 -24
- package/dist/core/stable-api-gateway.d.ts +0 -4
- package/dist/core/stable-api-gateway.d.ts.map +0 -1
- package/dist/core/stable-api-gateway.js +0 -136
- package/dist/core/stable-api-gateway.js.map +0 -1
- package/dist/core/stable-function.d.ts +0 -11
- package/dist/core/stable-function.d.ts.map +0 -1
- package/dist/core/stable-function.js +0 -340
- package/dist/core/stable-function.js.map +0 -1
- package/dist/core/stable-scheduler.d.ts +0 -71
- package/dist/core/stable-scheduler.d.ts.map +0 -1
- package/dist/core/stable-scheduler.js +0 -768
- package/dist/core/stable-scheduler.js.map +0 -1
- package/dist/core/stable-workflow-graph.d.ts +0 -3
- package/dist/core/stable-workflow-graph.d.ts.map +0 -1
- package/dist/core/stable-workflow-graph.js +0 -5
- package/dist/core/stable-workflow-graph.js.map +0 -1
- package/dist/core/stable-workflow.d.ts +0 -3
- package/dist/core/stable-workflow.d.ts.map +0 -1
- package/dist/core/stable-workflow.js +0 -362
- package/dist/core/stable-workflow.js.map +0 -1
- package/dist/stable-runner/index.d.ts +0 -2
- package/dist/stable-runner/index.d.ts.map +0 -1
- package/dist/stable-runner/index.js +0 -324
- package/dist/stable-runner/index.js.map +0 -1
- package/dist/utilities/concurrency-limiter.d.ts +0 -46
- package/dist/utilities/concurrency-limiter.d.ts.map +0 -1
- package/dist/utilities/concurrency-limiter.js +0 -172
- package/dist/utilities/concurrency-limiter.js.map +0 -1
- package/dist/utilities/execute-branch-workflow.d.ts +0 -3
- package/dist/utilities/execute-branch-workflow.d.ts.map +0 -1
- package/dist/utilities/execute-branch-workflow.js +0 -730
- package/dist/utilities/execute-branch-workflow.js.map +0 -1
- package/dist/utilities/execute-concurrently.d.ts +0 -3
- package/dist/utilities/execute-concurrently.d.ts.map +0 -1
- package/dist/utilities/execute-concurrently.js +0 -258
- package/dist/utilities/execute-concurrently.js.map +0 -1
- package/dist/utilities/execute-gateway-item.d.ts +0 -6
- package/dist/utilities/execute-gateway-item.d.ts.map +0 -1
- package/dist/utilities/execute-gateway-item.js +0 -127
- package/dist/utilities/execute-gateway-item.js.map +0 -1
- package/dist/utilities/execute-non-linear-workflow.d.ts +0 -3
- package/dist/utilities/execute-non-linear-workflow.d.ts.map +0 -1
- package/dist/utilities/execute-non-linear-workflow.js +0 -483
- package/dist/utilities/execute-non-linear-workflow.js.map +0 -1
- package/dist/utilities/execute-phase.d.ts +0 -3
- package/dist/utilities/execute-phase.d.ts.map +0 -1
- package/dist/utilities/execute-phase.js +0 -129
- package/dist/utilities/execute-phase.js.map +0 -1
- package/dist/utilities/execute-sequentially.d.ts +0 -3
- package/dist/utilities/execute-sequentially.d.ts.map +0 -1
- package/dist/utilities/execute-sequentially.js +0 -49
- package/dist/utilities/execute-sequentially.js.map +0 -1
- package/dist/utilities/execute-with-timeout.d.ts +0 -6
- package/dist/utilities/execute-with-timeout.d.ts.map +0 -1
- package/dist/utilities/execute-with-timeout.js +0 -28
- package/dist/utilities/execute-with-timeout.js.map +0 -1
- package/dist/utilities/execute-workflow-graph.d.ts +0 -3
- package/dist/utilities/execute-workflow-graph.d.ts.map +0 -1
- package/dist/utilities/execute-workflow-graph.js +0 -429
- package/dist/utilities/execute-workflow-graph.js.map +0 -1
- package/dist/utilities/extract-common-request-config-options.d.ts +0 -3
- package/dist/utilities/extract-common-request-config-options.d.ts.map +0 -1
- package/dist/utilities/extract-common-request-config-options.js +0 -12
- package/dist/utilities/extract-common-request-config-options.js.map +0 -1
- package/dist/utilities/fn-exec.d.ts +0 -3
- package/dist/utilities/fn-exec.d.ts.map +0 -1
- package/dist/utilities/fn-exec.js +0 -66
- package/dist/utilities/fn-exec.js.map +0 -1
- package/dist/utilities/function-cache-manager.d.ts +0 -32
- package/dist/utilities/function-cache-manager.d.ts.map +0 -1
- package/dist/utilities/function-cache-manager.js +0 -172
- package/dist/utilities/function-cache-manager.js.map +0 -1
- package/dist/utilities/prepare-api-function-options.d.ts +0 -3
- package/dist/utilities/prepare-api-function-options.d.ts.map +0 -1
- package/dist/utilities/prepare-api-function-options.js +0 -51
- package/dist/utilities/prepare-api-function-options.js.map +0 -1
- package/dist/utilities/prepare-api-request-data.d.ts +0 -3
- package/dist/utilities/prepare-api-request-data.d.ts.map +0 -1
- package/dist/utilities/prepare-api-request-data.js +0 -15
- package/dist/utilities/prepare-api-request-data.js.map +0 -1
- package/dist/utilities/prepare-api-request-options.d.ts +0 -3
- package/dist/utilities/prepare-api-request-options.d.ts.map +0 -1
- package/dist/utilities/prepare-api-request-options.js +0 -22
- package/dist/utilities/prepare-api-request-options.js.map +0 -1
- package/dist/utilities/rate-limiter.d.ts +0 -49
- package/dist/utilities/rate-limiter.d.ts.map +0 -1
- package/dist/utilities/rate-limiter.js +0 -197
- package/dist/utilities/rate-limiter.js.map +0 -1
- package/dist/utilities/validate-workflow-graph.d.ts +0 -7
- package/dist/utilities/validate-workflow-graph.d.ts.map +0 -1
- package/dist/utilities/validate-workflow-graph.js +0 -235
- package/dist/utilities/validate-workflow-graph.js.map +0 -1
- package/dist/utilities/workflow-graph-builder.d.ts +0 -37
- package/dist/utilities/workflow-graph-builder.d.ts.map +0 -1
- package/dist/utilities/workflow-graph-builder.js +0 -225
- package/dist/utilities/workflow-graph-builder.js.map +0 -1
|
@@ -1,483 +0,0 @@
|
|
|
1
|
-
import { executePhase } from './execute-phase.js';
|
|
2
|
-
import { executeWithPersistence } from './execute-with-persistence.js';
|
|
3
|
-
import { formatLogContext } from './format-log-context.js';
|
|
4
|
-
import { PHASE_DECISION_ACTIONS } from '../enums/index.js';
|
|
5
|
-
export async function executeNonLinearWorkflow(context) {
|
|
6
|
-
const { phases, startPhaseIndex, workflowId, branchId, commonGatewayOptions, requestGroups, logPhaseResults, handlePhaseCompletion, handlePhaseError, handlePhaseDecision, prePhaseExecutionHook, maxSerializableChars, workflowHookParams, sharedBuffer, stopOnFirstPhaseError, maxWorkflowIterations } = context;
|
|
7
|
-
const phaseResults = [];
|
|
8
|
-
const executionHistory = [];
|
|
9
|
-
const phaseExecutionCounts = new Map();
|
|
10
|
-
let totalRequests = 0;
|
|
11
|
-
let successfulRequests = 0;
|
|
12
|
-
let failedRequests = 0;
|
|
13
|
-
let terminatedEarly = false;
|
|
14
|
-
let terminationReason;
|
|
15
|
-
if (phases.length === 0) {
|
|
16
|
-
return {
|
|
17
|
-
phaseResults,
|
|
18
|
-
executionHistory,
|
|
19
|
-
totalRequests,
|
|
20
|
-
successfulRequests,
|
|
21
|
-
failedRequests,
|
|
22
|
-
terminatedEarly,
|
|
23
|
-
terminationReason
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
const phaseMap = new Map();
|
|
27
|
-
phases.forEach((phase, index) => {
|
|
28
|
-
const phaseId = phase.id || `phase-${index + 1}`;
|
|
29
|
-
phaseMap.set(phaseId, { phase, index });
|
|
30
|
-
});
|
|
31
|
-
let resolvedStartIndex = startPhaseIndex ?? 0;
|
|
32
|
-
if (resolvedStartIndex < 0 || resolvedStartIndex >= phases.length) {
|
|
33
|
-
throw new Error(`stable-request: startPhaseIndex ${resolvedStartIndex} is out of bounds for ${phases.length} phase(s)`);
|
|
34
|
-
}
|
|
35
|
-
if (phases[resolvedStartIndex]?.markConcurrentPhase) {
|
|
36
|
-
while (resolvedStartIndex > 0 && phases[resolvedStartIndex - 1]?.markConcurrentPhase) {
|
|
37
|
-
resolvedStartIndex--;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
let currentPhaseId = phases[resolvedStartIndex]?.id || `phase-${resolvedStartIndex + 1}`;
|
|
41
|
-
let iterationCount = 0;
|
|
42
|
-
while (currentPhaseId && iterationCount < maxWorkflowIterations) {
|
|
43
|
-
iterationCount++;
|
|
44
|
-
const phaseData = phaseMap.get(currentPhaseId);
|
|
45
|
-
if (!phaseData) {
|
|
46
|
-
if (logPhaseResults) {
|
|
47
|
-
console.error(`${formatLogContext({ workflowId, branchId })}stable-request: Phase '${currentPhaseId}' not found. Terminating workflow.`);
|
|
48
|
-
}
|
|
49
|
-
terminatedEarly = true;
|
|
50
|
-
terminationReason = `Phase '${currentPhaseId}' not found`;
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
const { phase, index: phaseIndex } = phaseData;
|
|
54
|
-
if (phase.markConcurrentPhase) {
|
|
55
|
-
const concurrentPhases = [];
|
|
56
|
-
let j = phaseIndex;
|
|
57
|
-
while (j < phases.length && phases[j].markConcurrentPhase) {
|
|
58
|
-
const concurrentPhaseId = phases[j].id || `phase-${j + 1}`;
|
|
59
|
-
concurrentPhases.push({
|
|
60
|
-
phase: phases[j],
|
|
61
|
-
index: j,
|
|
62
|
-
id: concurrentPhaseId
|
|
63
|
-
});
|
|
64
|
-
j++;
|
|
65
|
-
}
|
|
66
|
-
if (logPhaseResults) {
|
|
67
|
-
console.info(`\nstable-request: [Workflow: ${workflowId}] Executing ${concurrentPhases.length} phases in parallel: [${concurrentPhases.map(p => p.id).join(', ')}]`);
|
|
68
|
-
}
|
|
69
|
-
const concurrentPromises = concurrentPhases.map(({ phase: p, index: idx, id }) => {
|
|
70
|
-
const executionNumber = (phaseExecutionCounts.get(id) || 0) + 1;
|
|
71
|
-
phaseExecutionCounts.set(id, executionNumber);
|
|
72
|
-
return executePhase(p, idx, workflowId, commonGatewayOptions, requestGroups, logPhaseResults, handlePhaseCompletion, maxSerializableChars, workflowHookParams, sharedBuffer, branchId, prePhaseExecutionHook).then(result => ({
|
|
73
|
-
...result,
|
|
74
|
-
executionNumber,
|
|
75
|
-
phaseId: id,
|
|
76
|
-
phaseIndex: idx
|
|
77
|
-
})).catch(error => ({
|
|
78
|
-
workflowId,
|
|
79
|
-
...(branchId && { branchId }),
|
|
80
|
-
phaseId: id,
|
|
81
|
-
phaseIndex: idx,
|
|
82
|
-
success: false,
|
|
83
|
-
executionTime: 0,
|
|
84
|
-
timestamp: new Date().toISOString(),
|
|
85
|
-
totalRequests: 0,
|
|
86
|
-
successfulRequests: 0,
|
|
87
|
-
failedRequests: 0,
|
|
88
|
-
responses: [],
|
|
89
|
-
executionNumber: (phaseExecutionCounts.get(id) || 0),
|
|
90
|
-
error: error?.message || 'Phase execution failed'
|
|
91
|
-
}));
|
|
92
|
-
});
|
|
93
|
-
const concurrentResults = await Promise.all(concurrentPromises);
|
|
94
|
-
for (const phaseResult of concurrentResults) {
|
|
95
|
-
totalRequests += phaseResult.totalRequests;
|
|
96
|
-
successfulRequests += phaseResult.successfulRequests;
|
|
97
|
-
failedRequests += phaseResult.failedRequests;
|
|
98
|
-
phaseResults.push(phaseResult);
|
|
99
|
-
executionHistory.push({
|
|
100
|
-
phaseId: phaseResult.phaseId,
|
|
101
|
-
phaseIndex: phaseResult.phaseIndex,
|
|
102
|
-
executionNumber: phaseResult.executionNumber,
|
|
103
|
-
timestamp: phaseResult.timestamp,
|
|
104
|
-
success: phaseResult.success,
|
|
105
|
-
executionTime: phaseResult.executionTime
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
const hasFailures = concurrentResults.some(r => !r.success);
|
|
109
|
-
if (hasFailures && stopOnFirstPhaseError) {
|
|
110
|
-
if (logPhaseResults) {
|
|
111
|
-
console.error(`stable-request: [Workflow: ${workflowId}] One or more concurrent phases failed. Terminating workflow.`);
|
|
112
|
-
}
|
|
113
|
-
terminatedEarly = true;
|
|
114
|
-
terminationReason = `One or more concurrent phases failed`;
|
|
115
|
-
break;
|
|
116
|
-
}
|
|
117
|
-
const lastConcurrentPhase = concurrentPhases[concurrentPhases.length - 1];
|
|
118
|
-
const lastResult = concurrentResults[concurrentResults.length - 1];
|
|
119
|
-
let decision = {
|
|
120
|
-
action: PHASE_DECISION_ACTIONS.CONTINUE
|
|
121
|
-
};
|
|
122
|
-
if (lastConcurrentPhase.phase.phaseDecisionHook) {
|
|
123
|
-
try {
|
|
124
|
-
decision = await executeWithPersistence(lastConcurrentPhase.phase.phaseDecisionHook, {
|
|
125
|
-
workflowId,
|
|
126
|
-
...(branchId && { branchId }),
|
|
127
|
-
phaseResult: lastResult,
|
|
128
|
-
phaseId: lastConcurrentPhase.id,
|
|
129
|
-
phaseIndex: lastConcurrentPhase.index,
|
|
130
|
-
executionHistory,
|
|
131
|
-
sharedBuffer,
|
|
132
|
-
params: workflowHookParams?.handlePhaseDecisionParams,
|
|
133
|
-
concurrentPhaseResults: concurrentResults
|
|
134
|
-
}, lastConcurrentPhase.phase.statePersistence, { workflowId, branchId, phaseId: lastConcurrentPhase.id }, sharedBuffer);
|
|
135
|
-
if (!decision || typeof decision !== 'object') {
|
|
136
|
-
decision = { action: PHASE_DECISION_ACTIONS.CONTINUE };
|
|
137
|
-
}
|
|
138
|
-
if (logPhaseResults) {
|
|
139
|
-
console.info(`${formatLogContext({ workflowId, branchId })}stable-request: Concurrent group decision: ${decision.action}`, decision.targetPhaseId ? `-> ${decision.targetPhaseId}` : '');
|
|
140
|
-
}
|
|
141
|
-
if (handlePhaseDecision) {
|
|
142
|
-
try {
|
|
143
|
-
await executeWithPersistence(handlePhaseDecision, { decision, phaseResult: lastResult, maxSerializableChars }, workflowHookParams?.statePersistence, { workflowId, ...(branchId && { branchId }) }, sharedBuffer);
|
|
144
|
-
}
|
|
145
|
-
catch (hookError) {
|
|
146
|
-
console.error(`${formatLogContext({ workflowId, branchId })}stable-request: [Workflow: ${workflowId}] Error in handlePhaseDecision hook:`, hookError);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
catch (decisionError) {
|
|
151
|
-
console.error(`${formatLogContext({ workflowId, branchId })}stable-request: Error in phaseDecisionHook for concurrent group:`, decisionError);
|
|
152
|
-
decision = { action: PHASE_DECISION_ACTIONS.CONTINUE };
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
if (decision.addPhases && Array.isArray(decision.addPhases) && decision.addPhases.length > 0) {
|
|
156
|
-
if (logPhaseResults) {
|
|
157
|
-
console.info(`${formatLogContext({ workflowId, branchId })}stable-request: Adding ${decision.addPhases.length} dynamic phase(s) after concurrent group`);
|
|
158
|
-
}
|
|
159
|
-
decision.addPhases.forEach((newPhase, idx) => {
|
|
160
|
-
const newPhaseId = newPhase.id || `dynamic-phase-${Date.now()}-${idx}`;
|
|
161
|
-
const newPhaseWithId = {
|
|
162
|
-
...newPhase,
|
|
163
|
-
id: newPhaseId
|
|
164
|
-
};
|
|
165
|
-
const insertIndex = j + idx;
|
|
166
|
-
phases.splice(insertIndex, 0, newPhaseWithId);
|
|
167
|
-
phaseMap.set(newPhaseId, { phase: newPhaseWithId, index: insertIndex });
|
|
168
|
-
if (logPhaseResults) {
|
|
169
|
-
console.info(`${formatLogContext({ workflowId, branchId })}stable-request: Added dynamic phase '${newPhaseId}' at index ${insertIndex}`);
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
for (let i = j + decision.addPhases.length; i < phases.length; i++) {
|
|
173
|
-
const phId = phases[i].id || `phase-${i + 1}`;
|
|
174
|
-
const existingData = phaseMap.get(phId);
|
|
175
|
-
if (existingData) {
|
|
176
|
-
phaseMap.set(phId, { phase: existingData.phase, index: i });
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
switch (decision.action) {
|
|
181
|
-
case PHASE_DECISION_ACTIONS.TERMINATE:
|
|
182
|
-
if (logPhaseResults) {
|
|
183
|
-
console.info(`stable-request: [Workflow: ${workflowId}] Workflow terminated by decision hook.`, decision.metadata ? `Metadata: ${JSON.stringify(decision.metadata)}` : '');
|
|
184
|
-
}
|
|
185
|
-
terminatedEarly = true;
|
|
186
|
-
terminationReason = decision.metadata?.reason || 'Terminated by phase decision';
|
|
187
|
-
currentPhaseId = null;
|
|
188
|
-
break;
|
|
189
|
-
case PHASE_DECISION_ACTIONS.SKIP:
|
|
190
|
-
if (decision.targetPhaseId) {
|
|
191
|
-
currentPhaseId = decision.targetPhaseId;
|
|
192
|
-
}
|
|
193
|
-
else {
|
|
194
|
-
currentPhaseId = phases[j + 1]?.id || `phase-${j + 2}`;
|
|
195
|
-
if (j + 1 >= phases.length) {
|
|
196
|
-
currentPhaseId = null;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
break;
|
|
200
|
-
case PHASE_DECISION_ACTIONS.REPLAY:
|
|
201
|
-
if (logPhaseResults) {
|
|
202
|
-
console.warn(`${formatLogContext({ workflowId, branchId })}stable-request: Replay is not supported for concurrent phase groups. Continuing to next phase.`);
|
|
203
|
-
}
|
|
204
|
-
currentPhaseId = phases[j]?.id || `phase-${j + 1}`;
|
|
205
|
-
if (j >= phases.length) {
|
|
206
|
-
currentPhaseId = null;
|
|
207
|
-
}
|
|
208
|
-
break;
|
|
209
|
-
case PHASE_DECISION_ACTIONS.JUMP:
|
|
210
|
-
if (!decision.targetPhaseId) {
|
|
211
|
-
console.error(`${formatLogContext({ workflowId, branchId })}stable-request: Jump decision requires targetPhaseId. Continuing to next phase.`);
|
|
212
|
-
currentPhaseId = phases[j]?.id || `phase-${j + 1}`;
|
|
213
|
-
if (j >= phases.length) {
|
|
214
|
-
currentPhaseId = null;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
else {
|
|
218
|
-
currentPhaseId = decision.targetPhaseId;
|
|
219
|
-
}
|
|
220
|
-
break;
|
|
221
|
-
case PHASE_DECISION_ACTIONS.CONTINUE:
|
|
222
|
-
default:
|
|
223
|
-
currentPhaseId = phases[j]?.id || `phase-${j + 1}`;
|
|
224
|
-
if (j >= phases.length) {
|
|
225
|
-
currentPhaseId = null;
|
|
226
|
-
}
|
|
227
|
-
break;
|
|
228
|
-
}
|
|
229
|
-
continue;
|
|
230
|
-
}
|
|
231
|
-
const phaseId = currentPhaseId;
|
|
232
|
-
const executionNumber = (phaseExecutionCounts.get(phaseId) || 0) + 1;
|
|
233
|
-
phaseExecutionCounts.set(phaseId, executionNumber);
|
|
234
|
-
const maxReplayCount = phase.maxReplayCount ?? Infinity;
|
|
235
|
-
if (executionNumber > maxReplayCount + 1) {
|
|
236
|
-
if (logPhaseResults) {
|
|
237
|
-
console.warn(`${formatLogContext({ workflowId, branchId, phaseId })}stable-request: Phase '${phaseId}' exceeded max replay count (${maxReplayCount}). Skipping.`);
|
|
238
|
-
}
|
|
239
|
-
const skippedResult = {
|
|
240
|
-
workflowId,
|
|
241
|
-
...(branchId && { branchId }),
|
|
242
|
-
phaseId,
|
|
243
|
-
phaseIndex,
|
|
244
|
-
success: false,
|
|
245
|
-
executionTime: 0,
|
|
246
|
-
timestamp: new Date().toISOString(),
|
|
247
|
-
totalRequests: 0,
|
|
248
|
-
successfulRequests: 0,
|
|
249
|
-
failedRequests: 0,
|
|
250
|
-
responses: [],
|
|
251
|
-
executionNumber,
|
|
252
|
-
skipped: true,
|
|
253
|
-
error: `Exceeded max replay count (${maxReplayCount})`
|
|
254
|
-
};
|
|
255
|
-
phaseResults.push(skippedResult);
|
|
256
|
-
currentPhaseId = phases[phaseIndex + 1]?.id || `phase-${phaseIndex + 2}`;
|
|
257
|
-
if (phaseIndex + 1 >= phases.length) {
|
|
258
|
-
currentPhaseId = null;
|
|
259
|
-
}
|
|
260
|
-
continue;
|
|
261
|
-
}
|
|
262
|
-
if (logPhaseResults) {
|
|
263
|
-
const executionLabel = executionNumber > 1 ? ` (execution #${executionNumber})` : '';
|
|
264
|
-
console.info(`${formatLogContext({ workflowId, branchId, phaseId })}\nstable-request: Executing Phase '${phaseId}'${executionLabel}`);
|
|
265
|
-
}
|
|
266
|
-
try {
|
|
267
|
-
const phaseResult = await executePhase(phase, phaseIndex, workflowId, commonGatewayOptions, requestGroups, logPhaseResults, handlePhaseCompletion, maxSerializableChars, workflowHookParams, sharedBuffer, branchId, prePhaseExecutionHook);
|
|
268
|
-
phaseResult.executionNumber = executionNumber;
|
|
269
|
-
totalRequests += phaseResult.totalRequests;
|
|
270
|
-
successfulRequests += phaseResult.successfulRequests;
|
|
271
|
-
failedRequests += phaseResult.failedRequests;
|
|
272
|
-
phaseResults.push(phaseResult);
|
|
273
|
-
const historyRecord = {
|
|
274
|
-
phaseId,
|
|
275
|
-
phaseIndex,
|
|
276
|
-
executionNumber,
|
|
277
|
-
timestamp: phaseResult.timestamp,
|
|
278
|
-
success: phaseResult.success,
|
|
279
|
-
executionTime: phaseResult.executionTime
|
|
280
|
-
};
|
|
281
|
-
let decision = {
|
|
282
|
-
action: PHASE_DECISION_ACTIONS.CONTINUE
|
|
283
|
-
};
|
|
284
|
-
if (phase.phaseDecisionHook) {
|
|
285
|
-
try {
|
|
286
|
-
decision = await executeWithPersistence(phase.phaseDecisionHook, {
|
|
287
|
-
workflowId,
|
|
288
|
-
...(branchId && { branchId }),
|
|
289
|
-
phaseResult,
|
|
290
|
-
phaseId,
|
|
291
|
-
phaseIndex,
|
|
292
|
-
executionHistory,
|
|
293
|
-
sharedBuffer,
|
|
294
|
-
params: workflowHookParams?.handlePhaseDecisionParams
|
|
295
|
-
}, phase.statePersistence, { workflowId, branchId, phaseId }, sharedBuffer);
|
|
296
|
-
if (!decision || typeof decision !== 'object') {
|
|
297
|
-
decision = { action: PHASE_DECISION_ACTIONS.CONTINUE };
|
|
298
|
-
}
|
|
299
|
-
phaseResult.decision = decision;
|
|
300
|
-
historyRecord.decision = decision;
|
|
301
|
-
if (logPhaseResults) {
|
|
302
|
-
console.info(`${formatLogContext({ workflowId, branchId, phaseId })}stable-request: Phase '${phaseId}' decision: ${decision.action}`, decision.targetPhaseId ? `-> ${decision.targetPhaseId}` : '');
|
|
303
|
-
}
|
|
304
|
-
if (handlePhaseDecision) {
|
|
305
|
-
try {
|
|
306
|
-
await executeWithPersistence(handlePhaseDecision, { decision, phaseResult, maxSerializableChars }, workflowHookParams?.statePersistence, { workflowId, ...(branchId && { branchId }), phaseId }, sharedBuffer);
|
|
307
|
-
}
|
|
308
|
-
catch (hookError) {
|
|
309
|
-
console.error(`${formatLogContext({ workflowId, branchId, phaseId })}stable-request: [Workflow: ${workflowId}] Error in handlePhaseDecision hook:`, hookError);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
catch (decisionError) {
|
|
314
|
-
console.error(`${formatLogContext({ workflowId, branchId, phaseId })}stable-request: Error in phaseDecisionHook for phase '${phaseId}':`, decisionError);
|
|
315
|
-
decision = { action: PHASE_DECISION_ACTIONS.CONTINUE };
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
executionHistory.push(historyRecord);
|
|
319
|
-
if (decision.addPhases && Array.isArray(decision.addPhases) && decision.addPhases.length > 0) {
|
|
320
|
-
if (logPhaseResults) {
|
|
321
|
-
console.info(`${formatLogContext({ workflowId, branchId, phaseId })}stable-request: Adding ${decision.addPhases.length} dynamic phase(s) after '${phaseId}'`);
|
|
322
|
-
}
|
|
323
|
-
decision.addPhases.forEach((newPhase, idx) => {
|
|
324
|
-
const newPhaseId = newPhase.id || `dynamic-phase-${Date.now()}-${idx}`;
|
|
325
|
-
const newPhaseWithId = {
|
|
326
|
-
...newPhase,
|
|
327
|
-
id: newPhaseId
|
|
328
|
-
};
|
|
329
|
-
const insertIndex = phaseIndex + 1 + idx;
|
|
330
|
-
phases.splice(insertIndex, 0, newPhaseWithId);
|
|
331
|
-
phaseMap.set(newPhaseId, { phase: newPhaseWithId, index: insertIndex });
|
|
332
|
-
if (logPhaseResults) {
|
|
333
|
-
console.info(`${formatLogContext({ workflowId, branchId })}stable-request: Added dynamic phase '${newPhaseId}' at index ${insertIndex}`);
|
|
334
|
-
}
|
|
335
|
-
});
|
|
336
|
-
for (let i = phaseIndex + 1 + decision.addPhases.length; i < phases.length; i++) {
|
|
337
|
-
const phId = phases[i].id || `phase-${i + 1}`;
|
|
338
|
-
const existingData = phaseMap.get(phId);
|
|
339
|
-
if (existingData) {
|
|
340
|
-
phaseMap.set(phId, { phase: existingData.phase, index: i });
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
if (phaseResult.failedRequests > 0 && stopOnFirstPhaseError) {
|
|
345
|
-
if (logPhaseResults) {
|
|
346
|
-
console.error(`${formatLogContext({ workflowId, branchId, phaseId })}stable-request: [Workflow: ${workflowId}] Phase '${phaseId}' has failures. Stopping workflow due to stopOnFirstPhaseError.`);
|
|
347
|
-
}
|
|
348
|
-
terminatedEarly = true;
|
|
349
|
-
terminationReason = `Phase '${phaseId}' failed with ${phaseResult.failedRequests} failed requests`;
|
|
350
|
-
break;
|
|
351
|
-
}
|
|
352
|
-
switch (decision.action) {
|
|
353
|
-
case PHASE_DECISION_ACTIONS.TERMINATE:
|
|
354
|
-
if (logPhaseResults) {
|
|
355
|
-
console.info(`stable-request: [Workflow: ${workflowId}] Phase '${phaseId}' decided to terminate workflow.`);
|
|
356
|
-
}
|
|
357
|
-
terminatedEarly = true;
|
|
358
|
-
terminationReason = decision.metadata?.reason || 'Terminated by phase decision';
|
|
359
|
-
currentPhaseId = null;
|
|
360
|
-
break;
|
|
361
|
-
case PHASE_DECISION_ACTIONS.SKIP:
|
|
362
|
-
if (!phase.allowSkip && phase.allowSkip !== undefined) {
|
|
363
|
-
console.warn(`${formatLogContext({ workflowId, branchId, phaseId })}stable-request: Phase '${phaseId}' attempted to skip but allowSkip is false. Continuing normally.`);
|
|
364
|
-
currentPhaseId = phases[phaseIndex + 1]?.id || `phase-${phaseIndex + 2}`;
|
|
365
|
-
if (phaseIndex + 1 >= phases.length) {
|
|
366
|
-
currentPhaseId = null;
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
else {
|
|
370
|
-
if (decision.targetPhaseId) {
|
|
371
|
-
currentPhaseId = decision.targetPhaseId;
|
|
372
|
-
}
|
|
373
|
-
else {
|
|
374
|
-
currentPhaseId = phases[phaseIndex + 2]?.id || `phase-${phaseIndex + 3}`;
|
|
375
|
-
if (phaseIndex + 2 >= phases.length) {
|
|
376
|
-
currentPhaseId = null;
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
break;
|
|
381
|
-
case PHASE_DECISION_ACTIONS.REPLAY:
|
|
382
|
-
if (!phase.allowReplay && phase.allowReplay !== undefined) {
|
|
383
|
-
console.warn(`${formatLogContext({ workflowId, branchId, phaseId })}stable-request: Phase '${phaseId}' attempted to replay but allowReplay is false. Continuing normally.`);
|
|
384
|
-
currentPhaseId = phases[phaseIndex + 1]?.id || `phase-${phaseIndex + 2}`;
|
|
385
|
-
if (phaseIndex + 1 >= phases.length) {
|
|
386
|
-
currentPhaseId = null;
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
else {
|
|
390
|
-
currentPhaseId = phaseId;
|
|
391
|
-
}
|
|
392
|
-
break;
|
|
393
|
-
case PHASE_DECISION_ACTIONS.JUMP:
|
|
394
|
-
if (decision.targetPhaseId) {
|
|
395
|
-
currentPhaseId = decision.targetPhaseId;
|
|
396
|
-
}
|
|
397
|
-
else {
|
|
398
|
-
console.warn(`stable-request: [Workflow: ${workflowId}] Phase '${phaseId}' decided to jump but no targetPhaseId provided. Continuing normally.`);
|
|
399
|
-
currentPhaseId = phases[phaseIndex + 1]?.id || `phase-${phaseIndex + 2}`;
|
|
400
|
-
if (phaseIndex + 1 >= phases.length) {
|
|
401
|
-
currentPhaseId = null;
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
break;
|
|
405
|
-
case PHASE_DECISION_ACTIONS.CONTINUE:
|
|
406
|
-
default:
|
|
407
|
-
currentPhaseId = phases[phaseIndex + 1]?.id || `phase-${phaseIndex + 2}`;
|
|
408
|
-
if (phaseIndex + 1 >= phases.length) {
|
|
409
|
-
currentPhaseId = null;
|
|
410
|
-
}
|
|
411
|
-
break;
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
catch (phaseError) {
|
|
415
|
-
console.error(`${formatLogContext({ workflowId, branchId, phaseId })}stable-request: Error executing phase '${phaseId}':`, phaseError);
|
|
416
|
-
const errorResult = {
|
|
417
|
-
workflowId,
|
|
418
|
-
...(branchId && { branchId }),
|
|
419
|
-
phaseId,
|
|
420
|
-
phaseIndex,
|
|
421
|
-
success: false,
|
|
422
|
-
executionTime: 0,
|
|
423
|
-
timestamp: new Date().toISOString(),
|
|
424
|
-
totalRequests: 0,
|
|
425
|
-
successfulRequests: 0,
|
|
426
|
-
failedRequests: 0,
|
|
427
|
-
responses: [],
|
|
428
|
-
executionNumber,
|
|
429
|
-
error: phaseError?.message || 'Phase execution failed'
|
|
430
|
-
};
|
|
431
|
-
phaseResults.push(errorResult);
|
|
432
|
-
failedRequests += 1;
|
|
433
|
-
executionHistory.push({
|
|
434
|
-
phaseId,
|
|
435
|
-
phaseIndex,
|
|
436
|
-
executionNumber,
|
|
437
|
-
timestamp: errorResult.timestamp,
|
|
438
|
-
success: false,
|
|
439
|
-
executionTime: 0
|
|
440
|
-
});
|
|
441
|
-
try {
|
|
442
|
-
await executeWithPersistence(handlePhaseError, {
|
|
443
|
-
workflowId,
|
|
444
|
-
...(branchId && { branchId }),
|
|
445
|
-
phaseResult: errorResult,
|
|
446
|
-
error: phaseError,
|
|
447
|
-
maxSerializableChars,
|
|
448
|
-
params: workflowHookParams?.handlePhaseErrorParams,
|
|
449
|
-
sharedBuffer
|
|
450
|
-
}, workflowHookParams?.statePersistence, { workflowId, ...(branchId && { branchId }), phaseId }, sharedBuffer);
|
|
451
|
-
}
|
|
452
|
-
catch (hookError) {
|
|
453
|
-
console.error(`${formatLogContext({ workflowId, branchId, phaseId })}stable-request: Error in handlePhaseError hook:`, hookError);
|
|
454
|
-
}
|
|
455
|
-
if (stopOnFirstPhaseError) {
|
|
456
|
-
terminatedEarly = true;
|
|
457
|
-
terminationReason = `Phase '${phaseId}' encountered an error: ${phaseError?.message}`;
|
|
458
|
-
break;
|
|
459
|
-
}
|
|
460
|
-
currentPhaseId = phases[phaseIndex + 1]?.id || `phase-${phaseIndex + 2}`;
|
|
461
|
-
if (phaseIndex + 1 >= phases.length) {
|
|
462
|
-
currentPhaseId = null;
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
if (iterationCount >= maxWorkflowIterations && currentPhaseId) {
|
|
467
|
-
if (logPhaseResults) {
|
|
468
|
-
console.warn(`${formatLogContext({ workflowId, branchId })}stable-request: Reached max workflow iterations (${maxWorkflowIterations}). Terminating.`);
|
|
469
|
-
}
|
|
470
|
-
terminatedEarly = true;
|
|
471
|
-
terminationReason = `Exceeded maximum workflow iterations (${maxWorkflowIterations})`;
|
|
472
|
-
}
|
|
473
|
-
return {
|
|
474
|
-
phaseResults,
|
|
475
|
-
executionHistory,
|
|
476
|
-
totalRequests,
|
|
477
|
-
successfulRequests,
|
|
478
|
-
failedRequests,
|
|
479
|
-
terminatedEarly,
|
|
480
|
-
terminationReason
|
|
481
|
-
};
|
|
482
|
-
}
|
|
483
|
-
//# sourceMappingURL=execute-non-linear-workflow.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"execute-non-linear-workflow.js","sourceRoot":"","sources":["../../src/utilities/execute-non-linear-workflow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAU3D,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC5C,OAA0G;IAE1G,MAAM,EACJ,MAAM,EACN,eAAe,EACf,UAAU,EACV,QAAQ,EACR,oBAAoB,EACpB,aAAa,EACb,eAAe,EACf,qBAAqB,EACrB,gBAAgB,EAChB,mBAAmB,EACnB,qBAAqB,EACrB,oBAAoB,EACpB,kBAAkB,EAClB,YAAY,EACZ,qBAAqB,EACrB,qBAAqB,EACtB,GAAG,OAAO,CAAC;IAEZ,MAAM,YAAY,GAA4G,EAAE,CAAC;IACjI,MAAM,gBAAgB,GAAoG,EAAE,CAAC;IAC7H,MAAM,oBAAoB,GAAwB,IAAI,GAAG,EAAE,CAAC;IAE5D,IAAI,aAAa,GAAG,CAAC,CAAC;IACtB,IAAI,kBAAkB,GAAG,CAAC,CAAC;IAC3B,IAAI,cAAc,GAAG,CAAC,CAAC;IACvB,IAAI,e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Ac;QACd,eAAe;QACf,iBAAiB;KAClB,CAAC;AACJ,CAAC"}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { BufferLike, STABLE_WORKFLOW_PHASE, STABLE_WORKFLOW_PHASE_RESULT } from '../types/index.js';
|
|
2
|
-
export declare function executePhase<RequestDataType = any, ResponseDataType = any, FunctionArgsType extends any[] = any[], FunctionReturnType = any>(phase: STABLE_WORKFLOW_PHASE<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>, phaseIndex: number, workflowId: string, commonGatewayOptions: any, requestGroups: any[], logPhaseResults: boolean, handlePhaseCompletion: Function, maxSerializableChars: number, workflowHookParams: any, sharedBuffer?: BufferLike, branchId?: string, prePhaseExecutionHook?: Function): Promise<STABLE_WORKFLOW_PHASE_RESULT<ResponseDataType, FunctionReturnType, RequestDataType, FunctionArgsType>>;
|
|
3
|
-
//# sourceMappingURL=execute-phase.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"execute-phase.d.ts","sourceRoot":"","sources":["../../src/utilities/execute-phase.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,UAAU,EAAE,qBAAqB,EAAE,4BAA4B,EAAgC,MAAM,mBAAmB,CAAC;AAElI,wBAAsB,YAAY,CAAC,eAAe,GAAG,GAAG,EAAE,gBAAgB,GAAG,GAAG,EAAE,gBAAgB,SAAS,GAAG,EAAE,GAAG,GAAG,EAAE,EAAE,kBAAkB,GAAG,GAAG,EAC9I,KAAK,EAAE,qBAAqB,CAAC,eAAe,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,kBAAkB,CAAC,EACrG,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,oBAAoB,EAAE,GAAG,EACzB,aAAa,EAAE,GAAG,EAAE,EACpB,eAAe,EAAE,OAAO,EACxB,qBAAqB,EAAE,QAAQ,EAC/B,oBAAoB,EAAE,MAAM,EAC5B,kBAAkB,EAAE,GAAG,EACvB,YAAY,CAAC,EAAE,UAAU,EACzB,QAAQ,CAAC,EAAE,MAAM,EACjB,qBAAqB,CAAC,EAAE,QAAQ,kHA4CnC"}
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { stableApiGateway } from '../core/index.js';
|
|
2
|
-
import { executeWithPersistence } from './execute-with-persistence.js';
|
|
3
|
-
import { formatLogContext } from './format-log-context.js';
|
|
4
|
-
import { MetricsAggregator } from './metrics-aggregator.js';
|
|
5
|
-
import { MetricsValidator } from './metrics-validator.js';
|
|
6
|
-
import { RequestOrFunction } from '../enums/index.js';
|
|
7
|
-
export async function executePhase(phase, phaseIndex, workflowId, commonGatewayOptions, requestGroups, logPhaseResults, handlePhaseCompletion, maxSerializableChars, workflowHookParams, sharedBuffer, branchId, prePhaseExecutionHook) {
|
|
8
|
-
const phaseId = phase.id || `phase-${phaseIndex + 1}`;
|
|
9
|
-
if (phase.maxTimeout) {
|
|
10
|
-
const timeoutPromise = new Promise((_, reject) => {
|
|
11
|
-
setTimeout(() => {
|
|
12
|
-
const contextStr = `workflowId=${workflowId}${branchId ? `, branchId=${branchId}` : ''}, phaseId=${phaseId}`;
|
|
13
|
-
reject(new Error(`stable-request: Phase execution exceeded maxTimeout of ${phase.maxTimeout}ms [${contextStr}]`));
|
|
14
|
-
}, phase.maxTimeout);
|
|
15
|
-
});
|
|
16
|
-
const executionPromise = executePhaseInternal(phase, phaseIndex, workflowId, commonGatewayOptions, requestGroups, logPhaseResults, handlePhaseCompletion, maxSerializableChars, workflowHookParams, sharedBuffer, branchId, prePhaseExecutionHook);
|
|
17
|
-
return Promise.race([executionPromise, timeoutPromise]);
|
|
18
|
-
}
|
|
19
|
-
return executePhaseInternal(phase, phaseIndex, workflowId, commonGatewayOptions, requestGroups, logPhaseResults, handlePhaseCompletion, maxSerializableChars, workflowHookParams, sharedBuffer, branchId, prePhaseExecutionHook);
|
|
20
|
-
}
|
|
21
|
-
async function executePhaseInternal(phase, phaseIndex, workflowId, commonGatewayOptions, requestGroups, logPhaseResults, handlePhaseCompletion, maxSerializableChars, workflowHookParams, sharedBuffer, branchId, prePhaseExecutionHook) {
|
|
22
|
-
const phaseId = phase.id || `phase-${phaseIndex + 1}`;
|
|
23
|
-
let modifiedPhase = phase;
|
|
24
|
-
if (prePhaseExecutionHook) {
|
|
25
|
-
try {
|
|
26
|
-
const hookOptions = {
|
|
27
|
-
workflowId,
|
|
28
|
-
...(branchId && { branchId }),
|
|
29
|
-
phaseId,
|
|
30
|
-
phaseIndex,
|
|
31
|
-
phase: { ...phase },
|
|
32
|
-
sharedBuffer,
|
|
33
|
-
params: workflowHookParams?.prePhaseExecutionHookParams
|
|
34
|
-
};
|
|
35
|
-
const result = await executeWithPersistence(prePhaseExecutionHook, hookOptions, phase.statePersistence, { workflowId, branchId, phaseId }, sharedBuffer);
|
|
36
|
-
if (result) {
|
|
37
|
-
modifiedPhase = result;
|
|
38
|
-
console.info(`${formatLogContext({ workflowId, branchId, phaseId })}stable-request: Phase configuration modified by prePhaseExecutionHook`);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
catch (error) {
|
|
42
|
-
console.error(`${formatLogContext({ workflowId, branchId, phaseId })}stable-request: Error in prePhaseExecutionHook:`, error);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
const phaseStartTime = Date.now();
|
|
46
|
-
const phaseGatewayOptions = {
|
|
47
|
-
...commonGatewayOptions,
|
|
48
|
-
...(modifiedPhase.commonConfig || {}),
|
|
49
|
-
concurrentExecution: modifiedPhase.concurrentExecution ?? true,
|
|
50
|
-
stopOnFirstError: modifiedPhase.stopOnFirstError ?? false,
|
|
51
|
-
requestGroups,
|
|
52
|
-
sharedBuffer,
|
|
53
|
-
executionContext: {
|
|
54
|
-
workflowId,
|
|
55
|
-
...(branchId && { branchId }),
|
|
56
|
-
phaseId
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
if (modifiedPhase.maxConcurrentRequests !== undefined) {
|
|
60
|
-
phaseGatewayOptions.maxConcurrentRequests = modifiedPhase.maxConcurrentRequests;
|
|
61
|
-
}
|
|
62
|
-
if (modifiedPhase.rateLimit !== undefined) {
|
|
63
|
-
phaseGatewayOptions.rateLimit = modifiedPhase.rateLimit;
|
|
64
|
-
}
|
|
65
|
-
if (modifiedPhase.circuitBreaker !== undefined) {
|
|
66
|
-
phaseGatewayOptions.circuitBreaker = modifiedPhase.circuitBreaker;
|
|
67
|
-
}
|
|
68
|
-
if (!phaseGatewayOptions.commonExecutionTimeout && commonGatewayOptions.commonExecutionTimeout) {
|
|
69
|
-
phaseGatewayOptions.commonExecutionTimeout = commonGatewayOptions.commonExecutionTimeout;
|
|
70
|
-
}
|
|
71
|
-
let items = [];
|
|
72
|
-
if (modifiedPhase.items) {
|
|
73
|
-
items = modifiedPhase.items;
|
|
74
|
-
}
|
|
75
|
-
else if (modifiedPhase.functions) {
|
|
76
|
-
items = modifiedPhase.functions.map(fn => ({
|
|
77
|
-
type: RequestOrFunction.FUNCTION,
|
|
78
|
-
function: fn
|
|
79
|
-
}));
|
|
80
|
-
}
|
|
81
|
-
else if (modifiedPhase.requests) {
|
|
82
|
-
items = modifiedPhase.requests;
|
|
83
|
-
}
|
|
84
|
-
const phaseResponses = await stableApiGateway(items, phaseGatewayOptions);
|
|
85
|
-
const phaseExecutionTime = Date.now() - phaseStartTime;
|
|
86
|
-
const responses = Array.from(phaseResponses);
|
|
87
|
-
const phaseSuccessCount = responses.filter(r => r.success).length;
|
|
88
|
-
const phaseFailureCount = responses.filter(r => !r.success).length;
|
|
89
|
-
const phaseResult = {
|
|
90
|
-
workflowId,
|
|
91
|
-
...(branchId && { branchId }),
|
|
92
|
-
phaseId,
|
|
93
|
-
phaseIndex,
|
|
94
|
-
success: phaseFailureCount === 0,
|
|
95
|
-
executionTime: phaseExecutionTime,
|
|
96
|
-
timestamp: new Date(phaseStartTime).toISOString(),
|
|
97
|
-
totalRequests: responses.length,
|
|
98
|
-
successfulRequests: phaseSuccessCount,
|
|
99
|
-
failedRequests: phaseFailureCount,
|
|
100
|
-
responses: responses
|
|
101
|
-
};
|
|
102
|
-
phaseResult.metrics = MetricsAggregator.extractPhaseMetrics(phaseResult);
|
|
103
|
-
if (phaseResponses.metrics?.infrastructureMetrics) {
|
|
104
|
-
phaseResult.infrastructureMetrics = phaseResponses.metrics.infrastructureMetrics;
|
|
105
|
-
}
|
|
106
|
-
if (modifiedPhase.metricsGuardrails && phaseResult.metrics) {
|
|
107
|
-
phaseResult.validation = MetricsValidator.validatePhaseMetrics(phaseResult.metrics, modifiedPhase.metricsGuardrails);
|
|
108
|
-
}
|
|
109
|
-
if (logPhaseResults) {
|
|
110
|
-
console.info(`${formatLogContext({ workflowId, branchId, phaseId })}stable-request: Phase ${phaseId} completed:`, `${phaseSuccessCount}/${responses.length} successful`, `(${phaseExecutionTime}ms)`);
|
|
111
|
-
}
|
|
112
|
-
if (handlePhaseCompletion) {
|
|
113
|
-
try {
|
|
114
|
-
await executeWithPersistence(handlePhaseCompletion, {
|
|
115
|
-
workflowId,
|
|
116
|
-
...(branchId && { branchId }),
|
|
117
|
-
phaseResult,
|
|
118
|
-
maxSerializableChars,
|
|
119
|
-
params: workflowHookParams?.handlePhaseCompletionParams,
|
|
120
|
-
sharedBuffer
|
|
121
|
-
}, modifiedPhase.statePersistence, { workflowId, branchId, phaseId }, sharedBuffer);
|
|
122
|
-
}
|
|
123
|
-
catch (hookError) {
|
|
124
|
-
console.error(`${formatLogContext({ workflowId, branchId, phaseId })}stable-request: Error in handlePhaseCompletion hook:`, hookError);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
return phaseResult;
|
|
128
|
-
}
|
|
129
|
-
//# sourceMappingURL=execute-phase.js.map
|