arazzo-runner 0.0.3 → 0.0.5
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/README.md +28 -4
- package/package.json +1 -1
- package/src/Arazzo.js +131 -205
- package/src/Expression.js +0 -4
- package/src/Logger.js +7 -2
- package/src/Rules.js +40 -3
- package/.nyc_output/500b09aa-3263-4d30-a513-41e991b6d338.json +0 -1
- package/.nyc_output/processinfo/500b09aa-3263-4d30-a513-41e991b6d338.json +0 -1
- package/.nyc_output/processinfo/index.json +0 -1
- package/arazzo.json +0 -1
- package/pets-openAPI.json +0 -1
- package/users-arazzo.json +0 -1
- package/users-openAPI.json +0 -1
- package/usersOpenAPI.json +0 -1
package/README.md
CHANGED
|
@@ -63,6 +63,34 @@ jq --arg password "$secret_password" '.workflowId1.password = $password' input.j
|
|
|
63
63
|
|
|
64
64
|
Obviously, if you have a lot of secret variables that need adding as inputs, then you might need to write a script that can alter the `input.json` file for you within your CI/CD runner.
|
|
65
65
|
|
|
66
|
+
## Logging And Reporting
|
|
67
|
+
|
|
68
|
+
### Logging
|
|
69
|
+
|
|
70
|
+
Logging is currently pretty verbose, with an example Log looking like:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
Running Workflows
|
|
74
|
+
Running Workflow: createUser
|
|
75
|
+
Running Step: createAUser
|
|
76
|
+
Getting Source Description for: users-openAPI
|
|
77
|
+
Making a POST to http://petstore.swagger.io/v2/user
|
|
78
|
+
http://petstore.swagger.io/v2/user responded with a: 200
|
|
79
|
+
==================================================================================
|
|
80
|
+
Checking: $statusCode == 200
|
|
81
|
+
✅ $statusCode == 200 passed
|
|
82
|
+
==================================================================================
|
|
83
|
+
✅ All criteria checks passed
|
|
84
|
+
Running onSuccess Rules
|
|
85
|
+
✅ Step createAUser completed
|
|
86
|
+
✅ Workflow createUser completed
|
|
87
|
+
✅ All Workflows run
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Reporting
|
|
91
|
+
|
|
92
|
+
Work on Reporting still needs completeing.
|
|
93
|
+
|
|
66
94
|
## Still unsupported
|
|
67
95
|
|
|
68
96
|
### OpenAPI Params
|
|
@@ -84,7 +112,3 @@ Responses that do not conform to application/json do not work
|
|
|
84
112
|
### Non application/json Requests
|
|
85
113
|
|
|
86
114
|
Requests that do not conform to application/json do not work
|
|
87
|
-
|
|
88
|
-
#### Reporting && Logging
|
|
89
|
-
|
|
90
|
-
A better reporter/logger than console.log still needs to be implemented.
|
package/package.json
CHANGED
package/src/Arazzo.js
CHANGED
|
@@ -23,6 +23,7 @@ class Arazzo extends Document {
|
|
|
23
23
|
this.workflowRunRules = {};
|
|
24
24
|
this.retrySet = new Set();
|
|
25
25
|
this.retryLimits = {};
|
|
26
|
+
this.stepContext = {};
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
setMainArazzo() {
|
|
@@ -38,11 +39,11 @@ class Arazzo extends Document {
|
|
|
38
39
|
async runWorkflows(inputFile) {
|
|
39
40
|
await this.loadWorkflowData(inputFile);
|
|
40
41
|
|
|
41
|
-
|
|
42
|
+
this.logger.notice("Running Workflows");
|
|
42
43
|
|
|
43
44
|
await this.startWorkflows();
|
|
44
45
|
|
|
45
|
-
|
|
46
|
+
this.logger.success("All Workflows run");
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
async loadWorkflowData(inputFile) {
|
|
@@ -57,44 +58,24 @@ class Arazzo extends Document {
|
|
|
57
58
|
*/
|
|
58
59
|
async startWorkflows(index = 0) {
|
|
59
60
|
this.workflowIndex = index;
|
|
61
|
+
|
|
60
62
|
if (index <= this.workflows.length - 1) {
|
|
61
63
|
this.abortWorkflowController = new AbortController();
|
|
62
64
|
|
|
63
|
-
console.log("Running workflow index", index);
|
|
64
65
|
try {
|
|
65
66
|
await this.runWorkflow(index);
|
|
66
67
|
await this.startWorkflows(index + 1);
|
|
67
68
|
} catch (err) {
|
|
68
|
-
console.log("Caught");
|
|
69
|
-
// console.error(err);
|
|
70
|
-
|
|
71
69
|
if (err.name === "AbortError") {
|
|
72
70
|
if (err.goto) {
|
|
73
|
-
console.log("goto error");
|
|
71
|
+
// console.log("goto error");
|
|
74
72
|
await this.handleGotoRule(err.goto);
|
|
75
73
|
}
|
|
76
74
|
} else {
|
|
77
75
|
throw err;
|
|
78
76
|
}
|
|
79
77
|
}
|
|
80
|
-
// await this.runWorkflow(index).catch((err) => {
|
|
81
|
-
// console.log("caught", err);
|
|
82
|
-
// if (err.name === "AbortError") {
|
|
83
|
-
// } else {
|
|
84
|
-
// throw err;
|
|
85
|
-
// }
|
|
86
|
-
// });
|
|
87
|
-
|
|
88
|
-
// await this.startWorkflows(index + 1);
|
|
89
|
-
} else {
|
|
90
|
-
console.log("no more workflows");
|
|
91
78
|
}
|
|
92
|
-
// this.workflowIndex = index;
|
|
93
|
-
// const continueRunning = await this.runWorkflow(index);
|
|
94
|
-
|
|
95
|
-
// if (continueRunning.noMoreWorkflows === false) {
|
|
96
|
-
// await this.startWorkflows(index + 1);
|
|
97
|
-
// }
|
|
98
79
|
}
|
|
99
80
|
|
|
100
81
|
/**
|
|
@@ -109,21 +90,18 @@ class Arazzo extends Document {
|
|
|
109
90
|
this.abortWorkflowController = new AbortController();
|
|
110
91
|
}
|
|
111
92
|
|
|
112
|
-
const rules = new Rules(this.expression);
|
|
93
|
+
const rules = new Rules(this.expression, { logger: this.logger });
|
|
113
94
|
const workflow = await this.JSONPickerToIndex("workflows", index);
|
|
114
95
|
|
|
115
96
|
if (workflow) {
|
|
116
|
-
console.log(`Running Workflow: ${workflow.workflowId}`);
|
|
117
97
|
this.logger.notice(`Running Workflow: ${workflow.workflowId}`);
|
|
118
98
|
|
|
119
99
|
this.workflow = workflow;
|
|
100
|
+
this.workflowId = workflow.workflowId;
|
|
120
101
|
|
|
121
102
|
if (workflow.dependsOn) {
|
|
122
|
-
console.log(`${workflow.workflowId} has dependsOn`);
|
|
123
|
-
// console.log(this.expression.context);
|
|
124
103
|
await this.runDependsOnWorkflows();
|
|
125
|
-
|
|
126
|
-
console.log("end dependsOn");
|
|
104
|
+
|
|
127
105
|
this.workflow = workflow;
|
|
128
106
|
}
|
|
129
107
|
|
|
@@ -148,22 +126,22 @@ class Arazzo extends Document {
|
|
|
148
126
|
|
|
149
127
|
if (this.workflow.outputs) {
|
|
150
128
|
const outputs = {};
|
|
129
|
+
|
|
151
130
|
for (const key in this.workflow.outputs) {
|
|
152
131
|
const value = this.expression.resolveExpression(
|
|
153
132
|
this.workflow.outputs[key],
|
|
154
133
|
);
|
|
134
|
+
|
|
155
135
|
Object.assign(outputs, { [key]: value });
|
|
156
136
|
}
|
|
137
|
+
|
|
157
138
|
this.expression.addToContext("workflows", {
|
|
158
139
|
[this.workflow.workflowId]: { outputs: outputs },
|
|
159
140
|
});
|
|
160
141
|
}
|
|
161
142
|
|
|
143
|
+
this.logger.success(`Workflow ${workflow.workflowId} completed`);
|
|
162
144
|
return { noMoreWorkflows: false };
|
|
163
|
-
} else {
|
|
164
|
-
this.logger.notice(`All workflows have run`);
|
|
165
|
-
|
|
166
|
-
return { noMoreWorkflows: true };
|
|
167
145
|
}
|
|
168
146
|
}
|
|
169
147
|
|
|
@@ -171,7 +149,8 @@ class Arazzo extends Document {
|
|
|
171
149
|
* @private
|
|
172
150
|
*/
|
|
173
151
|
async runDependsOnWorkflows() {
|
|
174
|
-
|
|
152
|
+
this.logger.notice("Running Workflows from dependsOn");
|
|
153
|
+
|
|
175
154
|
for await (const workflowId of this.workflow.dependsOn) {
|
|
176
155
|
const workflowIndex = this.findWorkflowIndexByWorkflowId(workflowId);
|
|
177
156
|
|
|
@@ -179,7 +158,8 @@ class Arazzo extends Document {
|
|
|
179
158
|
await this.runWorkflow(workflowIndex);
|
|
180
159
|
}
|
|
181
160
|
}
|
|
182
|
-
|
|
161
|
+
|
|
162
|
+
this.logger.success("All Workflows from dependsOn have run");
|
|
183
163
|
}
|
|
184
164
|
|
|
185
165
|
/**
|
|
@@ -204,7 +184,6 @@ class Arazzo extends Document {
|
|
|
204
184
|
|
|
205
185
|
this.stepIndex = index;
|
|
206
186
|
if (index <= this.workflow?.steps?.length - 1) {
|
|
207
|
-
console.log("Running Step Index:", index);
|
|
208
187
|
await this.runStep(index);
|
|
209
188
|
await this.runSteps(index + 1);
|
|
210
189
|
}
|
|
@@ -224,7 +203,13 @@ class Arazzo extends Document {
|
|
|
224
203
|
|
|
225
204
|
if (step) {
|
|
226
205
|
this.step = step;
|
|
227
|
-
|
|
206
|
+
// if (!this.stepContext[step.stepId])
|
|
207
|
+
// Object.assign(this.stepContext, { [step.stepId]: {} });
|
|
208
|
+
|
|
209
|
+
this.logger.notice(`Running Step: ${step.stepId}`);
|
|
210
|
+
|
|
211
|
+
// need to deal with reloading the rules when in a retry state or a goto state
|
|
212
|
+
// if (this.stepContext?.[step.stepId]?.hasLoadedRules === false) {
|
|
228
213
|
if (this.step.onSuccess) {
|
|
229
214
|
this.workflow.rules.setStepSuccesses(this.step.onSuccess);
|
|
230
215
|
}
|
|
@@ -233,10 +218,11 @@ class Arazzo extends Document {
|
|
|
233
218
|
this.workflow.rules.setStepFailures(this.step.onFailure);
|
|
234
219
|
}
|
|
235
220
|
|
|
236
|
-
this.
|
|
221
|
+
// this.stepContext[step.stepId].hasLoadedRules = true;
|
|
222
|
+
// }
|
|
237
223
|
|
|
238
224
|
await this.loadOperationData();
|
|
239
|
-
|
|
225
|
+
|
|
240
226
|
if (this.openAPISteps) {
|
|
241
227
|
await this.runOpenAPIStep();
|
|
242
228
|
}
|
|
@@ -246,9 +232,10 @@ class Arazzo extends Document {
|
|
|
246
232
|
this.isAnOperationPath = false;
|
|
247
233
|
this.openAPISteps = false;
|
|
248
234
|
|
|
235
|
+
this.logger.success(`Step ${step.stepId} completed`);
|
|
249
236
|
return { noMoreSteps: false };
|
|
250
237
|
} else {
|
|
251
|
-
this.logger.notice(`All steps in ${this.workflow.workflowId} have run`);
|
|
238
|
+
// this.logger.notice(`All steps in ${this.workflow.workflowId} have run`);
|
|
252
239
|
|
|
253
240
|
return { noMoreSteps: true };
|
|
254
241
|
}
|
|
@@ -328,28 +315,32 @@ class Arazzo extends Document {
|
|
|
328
315
|
options.body = operation.data;
|
|
329
316
|
}
|
|
330
317
|
|
|
331
|
-
this.
|
|
332
|
-
|
|
333
|
-
|
|
318
|
+
if (this.retryAfter) {
|
|
319
|
+
this.logger.notice(
|
|
320
|
+
`retryAfter was set: waiting ${this.retryAfter * 1000} seconds`,
|
|
321
|
+
);
|
|
322
|
+
await sleep(this.retryAfter * 1000);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
this.expression.addToContext("url", url);
|
|
326
|
+
this.expression.addToContext("method", options.method);
|
|
334
327
|
|
|
335
|
-
|
|
328
|
+
this.logger.notice(`Making a ${options.method.toUpperCase()} to ${url}`);
|
|
336
329
|
|
|
337
|
-
console.log(`fetching: ${url}`);
|
|
338
|
-
console.log(options);
|
|
339
330
|
const response = await fetch(url, options);
|
|
340
331
|
|
|
341
332
|
if (response.headers.has("retry-after")) {
|
|
342
|
-
// assume seconds for now
|
|
343
|
-
// this.retryAfter = response.headers.get("retry-after");
|
|
344
333
|
const retryAfter = parseRetryAfter(response.headers.get("retry-after"));
|
|
345
334
|
if (retryAfter !== null) {
|
|
346
335
|
this.retryAfter = retryAfter;
|
|
347
336
|
}
|
|
348
337
|
}
|
|
349
338
|
|
|
350
|
-
this.addParamsToContext(response.headers, "
|
|
339
|
+
this.addParamsToContext(response.headers, "header", "response");
|
|
351
340
|
this.expression.addToContext("statusCode", response.status);
|
|
352
341
|
|
|
342
|
+
this.logger.notice(`${url} responded with a: ${response.status}`);
|
|
343
|
+
|
|
353
344
|
await this.dealWithResponse(response);
|
|
354
345
|
}
|
|
355
346
|
}
|
|
@@ -365,18 +356,19 @@ class Arazzo extends Document {
|
|
|
365
356
|
if (this.step.successCriteria) {
|
|
366
357
|
if (this.step.successCriteria) {
|
|
367
358
|
const passedSuccessCriteria = this.hasPassedSuccessCriteria();
|
|
368
|
-
|
|
359
|
+
|
|
369
360
|
if (passedSuccessCriteria) {
|
|
361
|
+
this.logger.success("All criteria checks passed");
|
|
370
362
|
if (this.currentRetryRule) {
|
|
371
363
|
if (this.retryContext.doNotDeleteRetryLimits) {
|
|
372
|
-
console.log("running", this.retryLimits);
|
|
373
364
|
this.retryLimits[this.currentRetryRule] = 0;
|
|
374
|
-
|
|
365
|
+
this.logger.notice("Retries stopped");
|
|
375
366
|
}
|
|
376
367
|
}
|
|
377
368
|
|
|
378
369
|
await this.dealWithPassedRule(response);
|
|
379
370
|
} else {
|
|
371
|
+
this.logger.error("Not all criteria checks passed");
|
|
380
372
|
if (this.step.onFailure) {
|
|
381
373
|
await this.dealWithFailedRule();
|
|
382
374
|
} else {
|
|
@@ -399,16 +391,37 @@ class Arazzo extends Document {
|
|
|
399
391
|
*/
|
|
400
392
|
hasPassedSuccessCriteria() {
|
|
401
393
|
const hasPassed = [];
|
|
394
|
+
this.logger.notice(
|
|
395
|
+
"==================================================================================",
|
|
396
|
+
);
|
|
402
397
|
for (const criteriaObject of this.step.successCriteria) {
|
|
403
398
|
if (criteriaObject?.type) {
|
|
399
|
+
if (criteriaObject.type === "regex") {
|
|
400
|
+
const hasPassedCheck = this.expression.checkRegexExpression(
|
|
401
|
+
criteriaObject.context,
|
|
402
|
+
criteriaObject.condition,
|
|
403
|
+
);
|
|
404
|
+
|
|
405
|
+
if (hasPassedCheck) hasPassed.push(true);
|
|
406
|
+
} else {
|
|
407
|
+
}
|
|
404
408
|
} else {
|
|
409
|
+
this.logger.notice(`Checking: ${criteriaObject.condition}`);
|
|
405
410
|
const hasPassedCheck = this.expression.checkSimpleExpression(
|
|
406
411
|
criteriaObject.condition,
|
|
407
412
|
);
|
|
408
|
-
|
|
413
|
+
|
|
414
|
+
if (hasPassedCheck) {
|
|
415
|
+
this.logger.success(`${criteriaObject.condition} passed`);
|
|
416
|
+
hasPassed.push(true);
|
|
417
|
+
} else {
|
|
418
|
+
this.logger.error(`${criteriaObject.condition} failed`);
|
|
419
|
+
}
|
|
409
420
|
}
|
|
410
421
|
}
|
|
411
|
-
|
|
422
|
+
this.logger.notice(
|
|
423
|
+
"==================================================================================",
|
|
424
|
+
);
|
|
412
425
|
return hasPassed.length === this.step.successCriteria.length;
|
|
413
426
|
}
|
|
414
427
|
|
|
@@ -421,62 +434,20 @@ class Arazzo extends Document {
|
|
|
421
434
|
await this.dealWithStepOutputs(response);
|
|
422
435
|
}
|
|
423
436
|
|
|
424
|
-
console.log("checking onSuccess rules");
|
|
425
437
|
const whatNext = this.workflow.rules.runRules(true);
|
|
426
|
-
|
|
438
|
+
|
|
427
439
|
if (whatNext.endWorkflow) {
|
|
428
440
|
this.workflowIndex += 1;
|
|
429
|
-
// const index = this.workflowIndex + 1;
|
|
430
441
|
|
|
431
|
-
console.log("ending workflow");
|
|
432
442
|
this.abortWorkflowController.abort();
|
|
443
|
+
this.logger.notice(
|
|
444
|
+
`${this.step.stepId} onSuccess End Workflow rule triggered`,
|
|
445
|
+
);
|
|
446
|
+
this.logger.notice(`Ending Workflow: ${this.workflowId}`);
|
|
433
447
|
throw new DOMException("Aborted", "AbortError");
|
|
434
|
-
console.log("still here though");
|
|
435
|
-
// this.abortStep = new AbortController();
|
|
436
|
-
// this.abortSignal = this.abortStep.signal;
|
|
437
|
-
|
|
438
|
-
// this.startWorkflows(index);
|
|
439
|
-
// this.abortSignal.addEventListener("abort", () => {
|
|
440
|
-
// console.log("in the listener");
|
|
441
|
-
// });
|
|
442
|
-
// console.log(this.abortSignal.aborted);
|
|
443
|
-
// console.log("back here");
|
|
444
448
|
} else if (whatNext.goto) {
|
|
445
|
-
|
|
449
|
+
this.logger.notice(`${this.step.stepId} onSuccess GoTo rule triggered`);
|
|
446
450
|
await this.gotoRule(whatNext);
|
|
447
|
-
console.log("onSuccess");
|
|
448
|
-
// if (whatNext.stepId) {
|
|
449
|
-
// // const stepIndex = this.workflow.steps.findIndex(
|
|
450
|
-
// // (step) => step.stepId === whatNext.stepId,
|
|
451
|
-
// // );
|
|
452
|
-
|
|
453
|
-
// // if (stepIndex === -1) {
|
|
454
|
-
// // throw new Error(`goto Step does not exist within current workflow`);
|
|
455
|
-
// // }
|
|
456
|
-
// const stepIndex = this.findStepIndexInWorkflowByStepId(whatNext.stepId);
|
|
457
|
-
|
|
458
|
-
// await this.runSteps(stepIndex);
|
|
459
|
-
// } else {
|
|
460
|
-
// // const workflowId = this.expression.resolveExpression(
|
|
461
|
-
// // whatNext.workflowId,
|
|
462
|
-
// // );
|
|
463
|
-
|
|
464
|
-
// // const workflowIndex = this.workflows.findIndex(
|
|
465
|
-
// // (workflow) => workflow.workflowId === workflowId,
|
|
466
|
-
// // );
|
|
467
|
-
|
|
468
|
-
// // if (workflowIndex === -1) {
|
|
469
|
-
// // throw new Error(
|
|
470
|
-
// // `goto Workflow does not exist within current workflows`,
|
|
471
|
-
// // );
|
|
472
|
-
// // }
|
|
473
|
-
// const workflowIndex = this.findWorkflowIndexByWorkflowId(
|
|
474
|
-
// whatNext.workflowId,
|
|
475
|
-
// );
|
|
476
|
-
// console.log("skipping to ", workflowIndex);
|
|
477
|
-
// await this.runWorkflow(workflowIndex);
|
|
478
|
-
// console.log("back at goto onSuccess");
|
|
479
|
-
// }
|
|
480
451
|
}
|
|
481
452
|
}
|
|
482
453
|
|
|
@@ -525,42 +496,23 @@ class Arazzo extends Document {
|
|
|
525
496
|
// await this.dealWithStepOutputs(response);
|
|
526
497
|
// }
|
|
527
498
|
|
|
528
|
-
console.log("checking onFailed rules");
|
|
529
499
|
const whatNext = this.workflow.rules.runRules();
|
|
530
500
|
if (whatNext.endWorkflow) {
|
|
531
501
|
this.workflowIndex += 1;
|
|
532
|
-
|
|
502
|
+
this.logger.notice(
|
|
503
|
+
`${this.step.stepId} onFailure End Workflow rule triggered`,
|
|
504
|
+
);
|
|
533
505
|
|
|
534
|
-
console.log("ending workflow");
|
|
535
506
|
this.abortWorkflowController.abort();
|
|
536
507
|
throw new DOMException("Aborted", "AbortError");
|
|
537
|
-
console.log("still here though");
|
|
538
508
|
} else if (whatNext.goto) {
|
|
539
|
-
|
|
509
|
+
this.logger.notice(`${this.step.stepId} onFailure GoTo rule triggered`);
|
|
540
510
|
await this.gotoRule(whatNext);
|
|
541
|
-
console.log("onFailure");
|
|
542
|
-
// if (whatNext.stepId) {
|
|
543
|
-
// // const stepIndex = this.workflow.steps.findIndex(
|
|
544
|
-
// // (step) => step.stepId === whatNext.stepId,
|
|
545
|
-
// // );
|
|
546
|
-
|
|
547
|
-
// // if (stepIndex === -1) {
|
|
548
|
-
// // throw new Error(`goto Step does not exist within current workflow`);
|
|
549
|
-
// // }
|
|
550
|
-
// //
|
|
551
|
-
// const stepIndex = this.findStepIndexInWorkflowByStepId(whatNext.stepId);
|
|
552
|
-
|
|
553
|
-
// await this.runSteps(stepIndex);
|
|
554
|
-
// } else {
|
|
555
|
-
// const workflowIndex = this.findWorkflowIndexByWorkflowId(
|
|
556
|
-
// whatNext.workflowId,
|
|
557
|
-
// );
|
|
558
|
-
// console.log("skipping to ", workflowIndex);
|
|
559
|
-
// await this.runWorkflow(workflowIndex);
|
|
560
|
-
// console.log("back at goto onFailure");
|
|
561
|
-
// }
|
|
562
511
|
} else {
|
|
563
|
-
|
|
512
|
+
if (this.retrySet.has(whatNext.name) === false)
|
|
513
|
+
this.logger.notice(
|
|
514
|
+
`${this.step.stepId} onFailure Retry rule triggered`,
|
|
515
|
+
);
|
|
564
516
|
await this.retryProcessing(whatNext);
|
|
565
517
|
}
|
|
566
518
|
}
|
|
@@ -571,67 +523,16 @@ class Arazzo extends Document {
|
|
|
571
523
|
*/
|
|
572
524
|
async gotoRule(gotoRule) {
|
|
573
525
|
if (gotoRule.stepId) {
|
|
574
|
-
console.log("goto stepId");
|
|
575
526
|
this.abortWorkflowController.abort();
|
|
576
527
|
|
|
577
528
|
// Attach goto to the error so we can handle it
|
|
578
529
|
const abortError = new DOMException("Aborted", "AbortError");
|
|
579
530
|
abortError.goto = gotoRule;
|
|
580
531
|
throw abortError;
|
|
581
|
-
|
|
582
|
-
// const stepIndex = this.workflow.steps.findIndex(
|
|
583
|
-
// (step) => step.stepId === whatNext.stepId,
|
|
584
|
-
// );
|
|
585
|
-
|
|
586
|
-
// if (stepIndex === -1) {
|
|
587
|
-
// throw new Error(`goto Step does not exist within current workflow`);
|
|
588
|
-
// }
|
|
589
|
-
|
|
590
|
-
// comment at 8:11am 12 Jan
|
|
591
|
-
// const stepIndex = this.findStepIndexInWorkflowByStepId(gotoRule.stepId);
|
|
592
|
-
// console.log("skipping to step", stepIndex);
|
|
593
|
-
// await this.runSteps(stepIndex);
|
|
594
|
-
|
|
595
|
-
// this.abortStepsController.abort();
|
|
596
|
-
// throw new DOMException("Aborted", "AbortError");
|
|
597
|
-
// this.abortStepsController.abort();
|
|
598
|
-
// throw new DOMException("Aborted", "AbortError");
|
|
599
|
-
|
|
600
|
-
// comment at 8:11am 12 Jan
|
|
601
|
-
// console.log("back at goto step");
|
|
602
532
|
} else {
|
|
603
533
|
const abortError = new DOMException("Aborted", "AbortError");
|
|
604
534
|
abortError.goto = gotoRule;
|
|
605
535
|
throw abortError;
|
|
606
|
-
|
|
607
|
-
// const workflowId = this.expression.resolveExpression(
|
|
608
|
-
// whatNext.workflowId,
|
|
609
|
-
// );
|
|
610
|
-
|
|
611
|
-
// const workflowIndex = this.workflows.findIndex(
|
|
612
|
-
// (workflow) => workflow.workflowId === workflowId,
|
|
613
|
-
// );
|
|
614
|
-
|
|
615
|
-
// if (workflowIndex === -1) {
|
|
616
|
-
// throw new Error(
|
|
617
|
-
// `goto Workflow does not exist within current workflows`,
|
|
618
|
-
// );
|
|
619
|
-
// }
|
|
620
|
-
|
|
621
|
-
// comment at 8:11am 12 Jan
|
|
622
|
-
// const workflowIndex = this.findWorkflowIndexByWorkflowId(
|
|
623
|
-
// gotoRule.workflowId,
|
|
624
|
-
// );
|
|
625
|
-
// console.log("skipping to workflow", workflowIndex);
|
|
626
|
-
// await this.runWorkflow(workflowIndex);
|
|
627
|
-
|
|
628
|
-
// this.abortStepsController.abort();
|
|
629
|
-
// throw new DOMException("Aborted", "AbortError");
|
|
630
|
-
// this.abortWorkflowController.abort();
|
|
631
|
-
// throw new DOMException("Aborted", "AbortError");
|
|
632
|
-
|
|
633
|
-
// comment at 8:11am 12 Jan
|
|
634
|
-
// console.log("back at goto workflow");
|
|
635
536
|
}
|
|
636
537
|
}
|
|
637
538
|
|
|
@@ -685,7 +586,28 @@ class Arazzo extends Document {
|
|
|
685
586
|
* @param {*} whatNext
|
|
686
587
|
*/
|
|
687
588
|
async retryProcessing(whatNext) {
|
|
688
|
-
|
|
589
|
+
const addOrdinalSuffix = function (num) {
|
|
590
|
+
// Validate input
|
|
591
|
+
if (typeof num !== "number" || !Number.isFinite(num)) {
|
|
592
|
+
throw new Error("Input must be a finite number.");
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
const absNum = Math.abs(num); // Handle negative numbers
|
|
596
|
+
const lastTwoDigits = absNum % 100;
|
|
597
|
+
const lastDigit = absNum % 10;
|
|
598
|
+
|
|
599
|
+
let suffix = "th"; // Default suffix
|
|
600
|
+
|
|
601
|
+
// Special case: 11, 12, 13 always use "th"
|
|
602
|
+
if (lastTwoDigits < 11 || lastTwoDigits > 13) {
|
|
603
|
+
if (lastDigit === 1) suffix = "st";
|
|
604
|
+
else if (lastDigit === 2) suffix = "nd";
|
|
605
|
+
else if (lastDigit === 3) suffix = "rd";
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
return `${num}${suffix}`;
|
|
609
|
+
};
|
|
610
|
+
|
|
689
611
|
this.retryContext = {
|
|
690
612
|
doNotDeleteRetryLimits: true,
|
|
691
613
|
};
|
|
@@ -694,10 +616,8 @@ class Arazzo extends Document {
|
|
|
694
616
|
this.currentRetryRule = whatNext.name;
|
|
695
617
|
|
|
696
618
|
if (this.retrySet.has(whatNext.name)) {
|
|
697
|
-
console.log("we are currently retrying this", whatNext.name);
|
|
698
619
|
shouldRunRule = false;
|
|
699
620
|
} else {
|
|
700
|
-
console.log("never retried this", whatNext.name);
|
|
701
621
|
this.retrySet.add(whatNext.name);
|
|
702
622
|
}
|
|
703
623
|
|
|
@@ -707,52 +627,64 @@ class Arazzo extends Document {
|
|
|
707
627
|
});
|
|
708
628
|
|
|
709
629
|
if (whatNext.stepId || whatNext.workflowId) {
|
|
710
|
-
console.log("need to run a workflow or step first");
|
|
711
630
|
this.retryContext.doNotDeleteRetryLimits = false;
|
|
631
|
+
|
|
712
632
|
if (whatNext.stepId) {
|
|
713
|
-
|
|
633
|
+
this.logger.notice(
|
|
634
|
+
`Rule ${whatNext.name} requires Step ${whatNext.stepId} running first`,
|
|
635
|
+
);
|
|
636
|
+
|
|
714
637
|
const stepIndex = this.findStepIndexInWorkflowByStepId(
|
|
715
638
|
whatNext.stepId,
|
|
716
639
|
);
|
|
717
640
|
|
|
718
641
|
await this.runStep(stepIndex);
|
|
719
|
-
|
|
642
|
+
|
|
643
|
+
this.logger.notice(
|
|
644
|
+
`Rule ${whatNext.name} Step ${whatNext.stepId} has run`,
|
|
645
|
+
);
|
|
720
646
|
} else {
|
|
647
|
+
this.logger.notice(
|
|
648
|
+
`Rule ${whatNext.name} requires Workflow ${whatNext.workflowId} running first`,
|
|
649
|
+
);
|
|
650
|
+
|
|
721
651
|
const workflowIndex = this.findWorkflowIndexByWorkflowId(
|
|
722
652
|
whatNext.workflowId,
|
|
723
653
|
);
|
|
724
654
|
|
|
725
|
-
console.log("need to run a workflow first");
|
|
726
655
|
await this.runWorkflow(workflowIndex);
|
|
727
|
-
|
|
656
|
+
|
|
657
|
+
this.logger.notice(
|
|
658
|
+
`Rule ${whatNext.name} Workflow ${whatNext.workflowId} has run`,
|
|
659
|
+
);
|
|
728
660
|
}
|
|
729
661
|
}
|
|
730
662
|
|
|
731
|
-
// this.retryContext.doNotDeleteRetryLimits = true;
|
|
732
|
-
|
|
733
663
|
if (!this.retryAfter && whatNext.retryAfter)
|
|
734
664
|
this.retryAfter = whatNext.retryAfter;
|
|
735
665
|
|
|
736
|
-
|
|
666
|
+
let counter = 1;
|
|
737
667
|
do {
|
|
738
|
-
|
|
668
|
+
this.logger.notice(
|
|
669
|
+
`Retrying ${this.step.stepId} for the ${addOrdinalSuffix(counter)} time`,
|
|
670
|
+
);
|
|
671
|
+
|
|
739
672
|
let count = this.retryLimits[whatNext.name];
|
|
740
|
-
|
|
673
|
+
|
|
741
674
|
await this.runStep(this.stepIndex);
|
|
742
|
-
console.log("I am back here");
|
|
743
675
|
|
|
744
676
|
if (this.retryLimits[whatNext.name] !== 0) {
|
|
745
677
|
count--;
|
|
678
|
+
counter++;
|
|
746
679
|
this.retryLimits[whatNext.name] = count;
|
|
747
680
|
}
|
|
748
681
|
} while (this.retryLimits[whatNext.name] > 0);
|
|
749
|
-
// }
|
|
750
682
|
}
|
|
751
683
|
|
|
752
684
|
if (this.retryLimits[whatNext.name] === 0)
|
|
753
685
|
this.retrySet.delete(whatNext.name);
|
|
754
686
|
|
|
755
|
-
console.log("I need to return here after retrying");
|
|
687
|
+
// console.log("I need to return here after retrying");
|
|
756
688
|
}
|
|
757
689
|
|
|
758
690
|
/**
|
|
@@ -774,6 +706,7 @@ class Arazzo extends Document {
|
|
|
774
706
|
|
|
775
707
|
Object.assign(outputs, { [key]: value });
|
|
776
708
|
}
|
|
709
|
+
|
|
777
710
|
this.expression.addToContext("steps", {
|
|
778
711
|
[this.step.stepId]: { outputs: outputs },
|
|
779
712
|
});
|
|
@@ -805,7 +738,7 @@ class Arazzo extends Document {
|
|
|
805
738
|
this.sourceDescription.operationDetails?.parameters
|
|
806
739
|
.filter((obj) => obj.name === param.name && obj.in === param.in)
|
|
807
740
|
.at(0);
|
|
808
|
-
|
|
741
|
+
|
|
809
742
|
const value = this.expression.resolveExpression(param.value);
|
|
810
743
|
|
|
811
744
|
switch (param.in) {
|
|
@@ -902,10 +835,8 @@ class Arazzo extends Document {
|
|
|
902
835
|
let workflowIdArr = this.step?.workflowId?.split(".") || [];
|
|
903
836
|
|
|
904
837
|
if (workflowIdArr.length === 1) {
|
|
905
|
-
console.log("run the workflow we just found");
|
|
906
838
|
await this.runWorkflowById(workflowIdArr.at(0));
|
|
907
839
|
} else {
|
|
908
|
-
console.log("running external arazzo", workflowIdArr.at(-1));
|
|
909
840
|
await this.sourceDescriptionFile.loadWorkflowData(this.inputFile);
|
|
910
841
|
await this.sourceDescriptionFile.runWorkflowById(workflowIdArr.at(-1));
|
|
911
842
|
}
|
|
@@ -959,7 +890,6 @@ class Arazzo extends Document {
|
|
|
959
890
|
this.isAnOperationId = true;
|
|
960
891
|
this.openAPISteps = true;
|
|
961
892
|
} else if (this.step.workflowId) {
|
|
962
|
-
console.log("i am here");
|
|
963
893
|
operationOrWorkflowPointer = this.step.workflowId;
|
|
964
894
|
this.isAWorkflowId = true;
|
|
965
895
|
} else {
|
|
@@ -995,8 +925,6 @@ class Arazzo extends Document {
|
|
|
995
925
|
},
|
|
996
926
|
});
|
|
997
927
|
}
|
|
998
|
-
// console.log(this.expression.context)
|
|
999
|
-
// this.expression.addToContext('sourceDescriptions', sourceDescriptions)
|
|
1000
928
|
}
|
|
1001
929
|
|
|
1002
930
|
/**
|
|
@@ -1024,9 +952,7 @@ class Arazzo extends Document {
|
|
|
1024
952
|
|
|
1025
953
|
async runWorkflowById(workflowId) {
|
|
1026
954
|
const workflowIndex = this.findWorkflowIndexByWorkflowId(workflowId);
|
|
1027
|
-
console.log(workflowIndex);
|
|
1028
955
|
await this.runWorkflow(workflowIndex);
|
|
1029
|
-
console.log("i got back here");
|
|
1030
956
|
}
|
|
1031
957
|
}
|
|
1032
958
|
|