@izara_project/izara-core-library-asynchronous-flow 1.0.51 → 1.0.53
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 +3 -3
- package/src/awaitingMultipleSteps.js +119 -126
- package/src/awaitingStep.js +42 -39
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"author": "Sven Mason <thebarbariansven@gmail.com>",
|
|
4
4
|
"license": "AGPL-3.0-or-later",
|
|
5
5
|
"homepage": "https://bitbucket.org/izara-core-libraries/izara-core-library-asynchronous-flow#readme",
|
|
6
|
-
"version": "1.0.
|
|
6
|
+
"version": "1.0.53",
|
|
7
7
|
"description": "Shared asynchronous flow logic",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"main": "index.js",
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
"url": "git+ssh://git@bitbucket.org/izara-core-libraries/izara-core-library-asynchronous-flow.git"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"@izara_project/izara-core-library-core": "^1.0.
|
|
19
|
-
"@izara_project/izara-core-library-dynamodb": "^1.0.
|
|
18
|
+
"@izara_project/izara-core-library-core": "^1.0.37",
|
|
19
|
+
"@izara_project/izara-core-library-dynamodb": "^1.0.23",
|
|
20
20
|
"@izara_project/izara-core-library-external-request": "^1.0.32",
|
|
21
21
|
"@izara_project/izara-core-library-logger": "^1.0.11",
|
|
22
22
|
"@izara_project/izara-core-library-sns": "^1.0.8",
|
|
@@ -14,20 +14,20 @@ You should have received a copy of the GNU Affero General Public License
|
|
|
14
14
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import { NoRetryError } from
|
|
18
|
-
import dynamodbSharedLib from
|
|
19
|
-
import { sns } from
|
|
20
|
-
import snsSharedLib from
|
|
17
|
+
import { NoRetryError } from '@izara_project/izara-core-library-core';
|
|
18
|
+
import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
|
|
19
|
+
import { sns } from '@izara_project/izara-core-library-external-request';
|
|
20
|
+
import snsSharedLib from '@izara_project/izara-core-library-sns';
|
|
21
21
|
|
|
22
22
|
import {
|
|
23
23
|
createParentFlowId,
|
|
24
24
|
createPendingStepId,
|
|
25
|
-
createAwaitingStepId
|
|
26
|
-
} from
|
|
25
|
+
createAwaitingStepId
|
|
26
|
+
} from './asyncFlowSharedLib.js';
|
|
27
27
|
|
|
28
28
|
function _assertPendingStepId(pendingStepId) {
|
|
29
29
|
if (!pendingStepId) {
|
|
30
|
-
throw new NoRetryError(
|
|
30
|
+
throw new NoRetryError('pendingStepId required');
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
|
|
@@ -35,15 +35,15 @@ async function _putAwaitingMultipleStepRecords(
|
|
|
35
35
|
_izContext,
|
|
36
36
|
records,
|
|
37
37
|
pendingStepId,
|
|
38
|
-
sharedAttributes = {}
|
|
38
|
+
sharedAttributes = {}
|
|
39
39
|
) {
|
|
40
40
|
const tableSteps = dynamodbSharedLib.tableName(
|
|
41
41
|
_izContext,
|
|
42
|
-
|
|
42
|
+
'AwaitingMultipleSteps'
|
|
43
43
|
);
|
|
44
44
|
const tablePending = dynamodbSharedLib.tableName(
|
|
45
45
|
_izContext,
|
|
46
|
-
|
|
46
|
+
'AwaitingMultipleStepByPending'
|
|
47
47
|
);
|
|
48
48
|
|
|
49
49
|
await Promise.all(
|
|
@@ -52,7 +52,7 @@ async function _putAwaitingMultipleStepRecords(
|
|
|
52
52
|
|
|
53
53
|
const itemPending = {
|
|
54
54
|
...keys,
|
|
55
|
-
...sharedAttributes
|
|
55
|
+
...sharedAttributes
|
|
56
56
|
};
|
|
57
57
|
if (additionalAttributes) {
|
|
58
58
|
if (sharedAttributes.additionalAttributes) {
|
|
@@ -67,21 +67,21 @@ async function _putAwaitingMultipleStepRecords(
|
|
|
67
67
|
|
|
68
68
|
return [
|
|
69
69
|
dynamodbSharedLib.putItem(_izContext, tableSteps, keys),
|
|
70
|
-
dynamodbSharedLib.putItem(_izContext, tablePending, itemPending)
|
|
70
|
+
dynamodbSharedLib.putItem(_izContext, tablePending, itemPending)
|
|
71
71
|
];
|
|
72
|
-
})
|
|
72
|
+
})
|
|
73
73
|
);
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
async function _queryPendingStepsByAwaitingStepId(_izContext, awaitingStepId) {
|
|
77
77
|
if (!awaitingStepId) {
|
|
78
|
-
throw new NoRetryError(
|
|
78
|
+
throw new NoRetryError('awaitingStepId required');
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
const { Items } = await dynamodbSharedLib.query(
|
|
82
82
|
_izContext,
|
|
83
|
-
dynamodbSharedLib.tableName(_izContext,
|
|
84
|
-
{ awaitingStepId }
|
|
83
|
+
dynamodbSharedLib.tableName(_izContext, 'AwaitingMultipleSteps'),
|
|
84
|
+
{ awaitingStepId }
|
|
85
85
|
);
|
|
86
86
|
|
|
87
87
|
return Items;
|
|
@@ -92,9 +92,9 @@ async function _queryAwaitingStepsByPendingStepId(_izContext, pendingStepId) {
|
|
|
92
92
|
|
|
93
93
|
const { Items } = await dynamodbSharedLib.query(
|
|
94
94
|
_izContext,
|
|
95
|
-
dynamodbSharedLib.tableName(_izContext,
|
|
95
|
+
dynamodbSharedLib.tableName(_izContext, 'AwaitingMultipleStepByPending'),
|
|
96
96
|
{ pendingStepId },
|
|
97
|
-
{ limit: 50 }
|
|
97
|
+
{ limit: 50 }
|
|
98
98
|
);
|
|
99
99
|
|
|
100
100
|
return Items;
|
|
@@ -127,37 +127,36 @@ async function _queryAwaitingStepsByPendingStepId(_izContext, pendingStepId) {
|
|
|
127
127
|
* @param {string} [options.flowType.serviceTag] - Default service tag.
|
|
128
128
|
* @returns {Promise<string|null>} The awaitingStepId of first record.
|
|
129
129
|
*/
|
|
130
|
-
|
|
130
|
+
async function createAwaitingMultipleSteps(
|
|
131
131
|
_izContext,
|
|
132
132
|
pendingStepId,
|
|
133
133
|
records = [],
|
|
134
|
-
options = {}
|
|
134
|
+
options = {}
|
|
135
135
|
) {
|
|
136
|
-
const { prefix =
|
|
136
|
+
const { prefix = '', additionalAttributes = {}, flowType = null } = options;
|
|
137
137
|
|
|
138
|
-
_izContext.logger.debug(
|
|
138
|
+
_izContext.logger.debug('[Lib:AsyncFlow:createAwaitingMultipleSteps] Input', {
|
|
139
139
|
pendingStepId,
|
|
140
|
-
options
|
|
140
|
+
options
|
|
141
141
|
});
|
|
142
142
|
|
|
143
143
|
const finalPendingStepId = createPendingStepId(pendingStepId, prefix);
|
|
144
144
|
|
|
145
|
-
const hasFlowPublish = flowType || records.some(
|
|
145
|
+
const hasFlowPublish = flowType || records.some(r => r.flowType);
|
|
146
146
|
|
|
147
147
|
let finalRecords = records;
|
|
148
148
|
|
|
149
149
|
if (finalRecords.length === 0 && !hasFlowPublish) {
|
|
150
150
|
finalRecords = [
|
|
151
151
|
{
|
|
152
|
-
awaitingStepId: createParentFlowId(
|
|
153
|
-
additionalAttributes
|
|
154
|
-
}
|
|
152
|
+
awaitingStepId: createParentFlowId(),
|
|
153
|
+
additionalAttributes
|
|
154
|
+
}
|
|
155
155
|
];
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
-
|
|
159
|
-
finalRecords = records.map(
|
|
160
|
-
|
|
158
|
+
if (hasFlowPublish) {
|
|
159
|
+
finalRecords = records.map(record => {
|
|
161
160
|
const recordFlowType = record.flowType || flowType;
|
|
162
161
|
|
|
163
162
|
if (
|
|
@@ -166,7 +165,7 @@ export async function createAwaitingMultipleSteps(
|
|
|
166
165
|
!recordFlowType.serviceTag
|
|
167
166
|
) {
|
|
168
167
|
throw new NoRetryError(
|
|
169
|
-
|
|
168
|
+
'record.flowType must have both flowTag and serviceTag'
|
|
170
169
|
);
|
|
171
170
|
}
|
|
172
171
|
|
|
@@ -181,13 +180,13 @@ export async function createAwaitingMultipleSteps(
|
|
|
181
180
|
additionalAttributes: record.additionalAttributes,
|
|
182
181
|
message: {
|
|
183
182
|
...record.message,
|
|
184
|
-
parentFlowId: awaitingStepId
|
|
183
|
+
parentFlowId: awaitingStepId
|
|
185
184
|
},
|
|
186
185
|
topicArn: snsSharedLib.snsTopicArnByFlowSchema(
|
|
187
186
|
_izContext,
|
|
188
187
|
recordFlowType.flowTag,
|
|
189
|
-
recordFlowType.serviceTag
|
|
190
|
-
)
|
|
188
|
+
recordFlowType.serviceTag
|
|
189
|
+
)
|
|
191
190
|
};
|
|
192
191
|
});
|
|
193
192
|
}
|
|
@@ -207,7 +206,7 @@ export async function createAwaitingMultipleSteps(
|
|
|
207
206
|
awaitingStepId: createAwaitingStepId(awaitingStepId, prefix),
|
|
208
207
|
additionalAttributes: mergedAttributes
|
|
209
208
|
};
|
|
210
|
-
}
|
|
209
|
+
}
|
|
211
210
|
);
|
|
212
211
|
|
|
213
212
|
await _putAwaitingMultipleStepRecords(
|
|
@@ -216,8 +215,8 @@ export async function createAwaitingMultipleSteps(
|
|
|
216
215
|
finalPendingStepId,
|
|
217
216
|
{
|
|
218
217
|
complete: false,
|
|
219
|
-
errorsFound: []
|
|
220
|
-
}
|
|
218
|
+
errorsFound: []
|
|
219
|
+
}
|
|
221
220
|
);
|
|
222
221
|
|
|
223
222
|
if (hasFlowPublish) {
|
|
@@ -225,9 +224,9 @@ export async function createAwaitingMultipleSteps(
|
|
|
225
224
|
finalRecords.map(async ({ message, topicArn }) => {
|
|
226
225
|
await sns.publishAsync(_izContext, {
|
|
227
226
|
TopicArn: `${topicArn}_In`,
|
|
228
|
-
Message: JSON.stringify(message)
|
|
227
|
+
Message: JSON.stringify(message)
|
|
229
228
|
});
|
|
230
|
-
})
|
|
229
|
+
})
|
|
231
230
|
);
|
|
232
231
|
}
|
|
233
232
|
|
|
@@ -246,27 +245,27 @@ export async function createAwaitingMultipleSteps(
|
|
|
246
245
|
* @param {object} data - Attributes to update.
|
|
247
246
|
* @returns {Promise<object>} The updated data with awaitingStepId merged.
|
|
248
247
|
*/
|
|
249
|
-
|
|
248
|
+
async function updateAwaitingMultipleStep(
|
|
250
249
|
_izContext,
|
|
251
250
|
awaitingStepId,
|
|
252
251
|
pendingStepId,
|
|
253
|
-
data
|
|
252
|
+
data
|
|
254
253
|
) {
|
|
255
254
|
const tableSteps = dynamodbSharedLib.tableName(
|
|
256
255
|
_izContext,
|
|
257
|
-
|
|
256
|
+
'AwaitingMultipleSteps'
|
|
258
257
|
);
|
|
259
258
|
|
|
260
259
|
await dynamodbSharedLib.updateItem(
|
|
261
260
|
_izContext,
|
|
262
261
|
tableSteps,
|
|
263
262
|
{ awaitingStepId, pendingStepId },
|
|
264
|
-
data
|
|
263
|
+
data
|
|
265
264
|
);
|
|
266
265
|
|
|
267
|
-
_izContext.logger.debug(
|
|
266
|
+
_izContext.logger.debug('[Lib:updateAwaitingMultipleStep] Output', {
|
|
268
267
|
awaitingStepId,
|
|
269
|
-
data
|
|
268
|
+
data
|
|
270
269
|
});
|
|
271
270
|
|
|
272
271
|
return { ...data, awaitingStepId };
|
|
@@ -279,17 +278,17 @@ export async function updateAwaitingMultipleStep(
|
|
|
279
278
|
* @param {string} awaitingStepId - The ID of the awaiting step.
|
|
280
279
|
* @returns {Promise<object|null>} The found item or null.
|
|
281
280
|
*/
|
|
282
|
-
|
|
281
|
+
async function findPendingStepAwaitingMultipleSteps(
|
|
283
282
|
_izContext,
|
|
284
|
-
awaitingStepId
|
|
283
|
+
awaitingStepId
|
|
285
284
|
) {
|
|
286
|
-
_izContext.logger.debug(
|
|
287
|
-
awaitingStepId
|
|
285
|
+
_izContext.logger.debug('[Lib:findPendingStepAwaitingMultipleSteps] Input', {
|
|
286
|
+
awaitingStepId
|
|
288
287
|
});
|
|
289
288
|
|
|
290
289
|
const items = await _queryPendingStepsByAwaitingStepId(
|
|
291
290
|
_izContext,
|
|
292
|
-
awaitingStepId
|
|
291
|
+
awaitingStepId
|
|
293
292
|
);
|
|
294
293
|
|
|
295
294
|
if (items && items.length > 0) {
|
|
@@ -305,9 +304,9 @@ export async function findPendingStepAwaitingMultipleSteps(
|
|
|
305
304
|
* @param {string} awaitingStepId - The ID of the awaiting step.
|
|
306
305
|
* @returns {Promise<Array<object>>} List of matching items.
|
|
307
306
|
*/
|
|
308
|
-
|
|
307
|
+
async function findPendingStepsAwaitingMultipleSteps(
|
|
309
308
|
_izContext,
|
|
310
|
-
awaitingStepId
|
|
309
|
+
awaitingStepId
|
|
311
310
|
) {
|
|
312
311
|
return _queryPendingStepsByAwaitingStepId(_izContext, awaitingStepId);
|
|
313
312
|
}
|
|
@@ -319,13 +318,13 @@ export async function findPendingStepsAwaitingMultipleSteps(
|
|
|
319
318
|
* @param {string} awaitingStepId - The ID of the awaiting step.
|
|
320
319
|
* @returns {Promise<string|null>} pendingStepId of first item found or null.
|
|
321
320
|
*/
|
|
322
|
-
|
|
321
|
+
async function findPendingStepIdAwaitingMultipleSteps(
|
|
323
322
|
_izContext,
|
|
324
|
-
awaitingStepId
|
|
323
|
+
awaitingStepId
|
|
325
324
|
) {
|
|
326
325
|
const items = await _queryPendingStepsByAwaitingStepId(
|
|
327
326
|
_izContext,
|
|
328
|
-
awaitingStepId
|
|
327
|
+
awaitingStepId
|
|
329
328
|
);
|
|
330
329
|
if (items && items[0] && items[0].pendingStepId) {
|
|
331
330
|
return items[0].pendingStepId;
|
|
@@ -340,10 +339,7 @@ export async function findPendingStepIdAwaitingMultipleSteps(
|
|
|
340
339
|
* @param {string} pendingStepId - The ID of the pending step.
|
|
341
340
|
* @returns {Promise<Array<object>>} List of matching items.
|
|
342
341
|
*/
|
|
343
|
-
|
|
344
|
-
_izContext,
|
|
345
|
-
pendingStepId,
|
|
346
|
-
) {
|
|
342
|
+
async function findAwaitingMultipleStepByPending(_izContext, pendingStepId) {
|
|
347
343
|
return _queryAwaitingStepsByPendingStepId(_izContext, pendingStepId);
|
|
348
344
|
}
|
|
349
345
|
|
|
@@ -359,22 +355,22 @@ export async function findAwaitingMultipleStepByPending(
|
|
|
359
355
|
* @param {boolean} [settings.checkIsAllError=false] - Verify all failed.
|
|
360
356
|
* @returns {Promise<object>} Status object containing completion details.
|
|
361
357
|
*/
|
|
362
|
-
|
|
358
|
+
async function checkAllAwaitingStepsFinishedWithReturnParams(
|
|
363
359
|
_izContext,
|
|
364
360
|
pendingStepId,
|
|
365
361
|
currentAwaitingStepId,
|
|
366
362
|
errorsFound = [],
|
|
367
363
|
returnValues = {},
|
|
368
|
-
settings = { checkIsAllError: false }
|
|
364
|
+
settings = { checkIsAllError: false }
|
|
369
365
|
) {
|
|
370
366
|
_izContext.logger.debug(
|
|
371
|
-
|
|
367
|
+
'[Lib:checkAllAwaitingStepsFinishedWithReturnParams] Input parameters',
|
|
372
368
|
{
|
|
373
369
|
pendingStepId,
|
|
374
370
|
currentAwaitingStepId,
|
|
375
371
|
errorsFound,
|
|
376
|
-
returnValues
|
|
377
|
-
}
|
|
372
|
+
returnValues
|
|
373
|
+
}
|
|
378
374
|
);
|
|
379
375
|
|
|
380
376
|
_assertPendingStepId(pendingStepId);
|
|
@@ -393,26 +389,16 @@ export async function checkAllAwaitingStepsFinishedWithReturnParams(
|
|
|
393
389
|
|
|
394
390
|
await dynamodbSharedLib.updateItem(
|
|
395
391
|
_izContext,
|
|
396
|
-
dynamodbSharedLib.tableName(_izContext,
|
|
392
|
+
dynamodbSharedLib.tableName(_izContext, 'AwaitingMultipleStepByPending'),
|
|
397
393
|
{
|
|
398
394
|
pendingStepId,
|
|
399
|
-
awaitingStepId: currentAwaitingStepId
|
|
395
|
+
awaitingStepId: currentAwaitingStepId
|
|
400
396
|
},
|
|
401
397
|
{
|
|
402
398
|
complete: true,
|
|
403
399
|
errorsFound,
|
|
404
|
-
returnValues
|
|
405
|
-
}
|
|
406
|
-
);
|
|
407
|
-
|
|
408
|
-
_izContext.logger.debug(
|
|
409
|
-
'[Lib:checkAllAwaitingStepsFinishedWithReturnParams] After updating awaitingStepItems',
|
|
410
|
-
{
|
|
411
|
-
pendingStepId,
|
|
412
|
-
awaitingStepId: currentAwaitingStepId,
|
|
413
|
-
errorsFound,
|
|
414
|
-
returnValues,
|
|
415
|
-
},
|
|
400
|
+
returnValues
|
|
401
|
+
}
|
|
416
402
|
);
|
|
417
403
|
|
|
418
404
|
_izContext.logger.debug(
|
|
@@ -428,11 +414,11 @@ export async function checkAllAwaitingStepsFinishedWithReturnParams(
|
|
|
428
414
|
|
|
429
415
|
const awaitingStepItems = await _queryAwaitingStepsByPendingStepId(
|
|
430
416
|
_izContext,
|
|
431
|
-
pendingStepId
|
|
417
|
+
pendingStepId
|
|
432
418
|
);
|
|
433
419
|
|
|
434
420
|
_izContext.logger.debug(
|
|
435
|
-
|
|
421
|
+
'[Lib:checkAllAwaitingStepsFinishedWithReturnParams] awaitingStepItems',
|
|
436
422
|
{ awaitingStepItems },
|
|
437
423
|
'[Lib:checkAllAwaitingStepsFinishedWithReturnParams] Queried awaitingStepItems',
|
|
438
424
|
{
|
|
@@ -459,7 +445,7 @@ export async function checkAllAwaitingStepsFinishedWithReturnParams(
|
|
|
459
445
|
}
|
|
460
446
|
|
|
461
447
|
const hasIncomplete = awaitingStepItems.some(
|
|
462
|
-
|
|
448
|
+
item => item.awaitingStepId !== currentAwaitingStepId && !item.complete
|
|
463
449
|
);
|
|
464
450
|
|
|
465
451
|
let defaultAttrs = null;
|
|
@@ -530,7 +516,7 @@ export async function checkAllAwaitingStepsFinishedWithReturnParams(
|
|
|
530
516
|
collectedReturnValueByAwaitingStepId: null,
|
|
531
517
|
collectedErrors: [],
|
|
532
518
|
returnValues: null,
|
|
533
|
-
additionalAttributes: defaultAttrs
|
|
519
|
+
additionalAttributes: defaultAttrs
|
|
534
520
|
};
|
|
535
521
|
}
|
|
536
522
|
|
|
@@ -554,7 +540,7 @@ export async function checkAllAwaitingStepsFinishedWithReturnParams(
|
|
|
554
540
|
if (item.errorsFound && item.errorsFound.length > 0) {
|
|
555
541
|
collectedErrors.push(
|
|
556
542
|
`Error found in step ${item.awaitingStepId}`,
|
|
557
|
-
...item.errorsFound
|
|
543
|
+
...item.errorsFound
|
|
558
544
|
);
|
|
559
545
|
}
|
|
560
546
|
}
|
|
@@ -564,12 +550,12 @@ export async function checkAllAwaitingStepsFinishedWithReturnParams(
|
|
|
564
550
|
collectedReturnValueByAwaitingStepId,
|
|
565
551
|
collectedErrors,
|
|
566
552
|
returnValues: sharedReturnValues,
|
|
567
|
-
additionalAttributes: defaultAttrs
|
|
553
|
+
additionalAttributes: defaultAttrs
|
|
568
554
|
};
|
|
569
555
|
|
|
570
556
|
if (settings.checkIsAllError) {
|
|
571
557
|
result.isAllError = awaitingStepItems.every(
|
|
572
|
-
|
|
558
|
+
item => item.errorsFound && item.errorsFound.length > 0
|
|
573
559
|
);
|
|
574
560
|
}
|
|
575
561
|
|
|
@@ -591,22 +577,22 @@ export async function checkAllAwaitingStepsFinishedWithReturnParams(
|
|
|
591
577
|
* @param {string} pendingStepId - The ID of the pending step.
|
|
592
578
|
* @returns {Promise<boolean>} True if operations completed successfully.
|
|
593
579
|
*/
|
|
594
|
-
|
|
595
|
-
_izContext.logger.debug(
|
|
596
|
-
pendingStepId
|
|
580
|
+
async function clearAllAwaitingSteps(_izContext, pendingStepId) {
|
|
581
|
+
_izContext.logger.debug('[Lib:clearAllAwaitingSteps] Input parameters', {
|
|
582
|
+
pendingStepId
|
|
597
583
|
});
|
|
598
584
|
|
|
599
585
|
const awaitingStepItems = await _queryAwaitingStepsByPendingStepId(
|
|
600
586
|
_izContext,
|
|
601
|
-
pendingStepId
|
|
587
|
+
pendingStepId
|
|
602
588
|
);
|
|
603
589
|
const tableSteps = dynamodbSharedLib.tableName(
|
|
604
590
|
_izContext,
|
|
605
|
-
|
|
591
|
+
'AwaitingMultipleSteps'
|
|
606
592
|
);
|
|
607
593
|
const tablePending = dynamodbSharedLib.tableName(
|
|
608
594
|
_izContext,
|
|
609
|
-
|
|
595
|
+
'AwaitingMultipleStepByPending'
|
|
610
596
|
);
|
|
611
597
|
|
|
612
598
|
await Promise.all(
|
|
@@ -614,14 +600,14 @@ export async function clearAllAwaitingSteps(_izContext, pendingStepId) {
|
|
|
614
600
|
({ awaitingStepId, pendingStepId: itemPendingStepId }) => [
|
|
615
601
|
dynamodbSharedLib.deleteItem(_izContext, tableSteps, {
|
|
616
602
|
awaitingStepId,
|
|
617
|
-
pendingStepId: itemPendingStepId
|
|
603
|
+
pendingStepId: itemPendingStepId
|
|
618
604
|
}),
|
|
619
605
|
dynamodbSharedLib.deleteItem(_izContext, tablePending, {
|
|
620
606
|
awaitingStepId,
|
|
621
|
-
pendingStepId: itemPendingStepId
|
|
622
|
-
})
|
|
623
|
-
]
|
|
624
|
-
)
|
|
607
|
+
pendingStepId: itemPendingStepId
|
|
608
|
+
})
|
|
609
|
+
]
|
|
610
|
+
)
|
|
625
611
|
);
|
|
626
612
|
|
|
627
613
|
return true;
|
|
@@ -636,16 +622,16 @@ export async function clearAllAwaitingSteps(_izContext, pendingStepId) {
|
|
|
636
622
|
* @param {Array<any>} [errorsFound=[]] - List of errors.
|
|
637
623
|
* @returns {Promise<void>}
|
|
638
624
|
*/
|
|
639
|
-
|
|
625
|
+
async function removeAwaitingMultipleStep(
|
|
640
626
|
_izContext,
|
|
641
627
|
awaitingStepId,
|
|
642
628
|
pendingStepId,
|
|
643
|
-
errorsFound = []
|
|
629
|
+
errorsFound = []
|
|
644
630
|
) {
|
|
645
|
-
_izContext.logger.debug(
|
|
631
|
+
_izContext.logger.debug('[Lib:removeAwaitingMultipleStep] Input parameters', {
|
|
646
632
|
awaitingStepId,
|
|
647
633
|
pendingStepId,
|
|
648
|
-
errorsFound
|
|
634
|
+
errorsFound
|
|
649
635
|
});
|
|
650
636
|
|
|
651
637
|
if (!awaitingStepId || !pendingStepId) {
|
|
@@ -659,9 +645,9 @@ export async function removeAwaitingMultipleStep(
|
|
|
659
645
|
const promises = [
|
|
660
646
|
dynamodbSharedLib.deleteItem(
|
|
661
647
|
_izContext,
|
|
662
|
-
dynamodbSharedLib.tableName(_izContext,
|
|
663
|
-
keys
|
|
664
|
-
)
|
|
648
|
+
dynamodbSharedLib.tableName(_izContext, 'AwaitingMultipleSteps'),
|
|
649
|
+
keys
|
|
650
|
+
)
|
|
665
651
|
];
|
|
666
652
|
|
|
667
653
|
if (errorsFound.length === 0) {
|
|
@@ -670,10 +656,10 @@ export async function removeAwaitingMultipleStep(
|
|
|
670
656
|
_izContext,
|
|
671
657
|
dynamodbSharedLib.tableName(
|
|
672
658
|
_izContext,
|
|
673
|
-
|
|
659
|
+
'AwaitingMultipleStepByPending'
|
|
674
660
|
),
|
|
675
|
-
keys
|
|
676
|
-
)
|
|
661
|
+
keys
|
|
662
|
+
)
|
|
677
663
|
);
|
|
678
664
|
}
|
|
679
665
|
|
|
@@ -687,10 +673,10 @@ export async function removeAwaitingMultipleStep(
|
|
|
687
673
|
* @param {string} parentFlowId - The ID of the parent flow.
|
|
688
674
|
* @returns {Promise<Object>} Status object containing completion details.
|
|
689
675
|
*/
|
|
690
|
-
|
|
676
|
+
async function completeAction(
|
|
691
677
|
_izContext,
|
|
692
678
|
parentFlowId,
|
|
693
|
-
prefix =
|
|
679
|
+
prefix = '',
|
|
694
680
|
returnValue = {},
|
|
695
681
|
errorsFound = [],
|
|
696
682
|
settings = { checkIsAllError: false }
|
|
@@ -701,17 +687,14 @@ export async function completeAction(
|
|
|
701
687
|
});
|
|
702
688
|
|
|
703
689
|
try {
|
|
704
|
-
const {pendingStepId} = await findPendingStepAwaitingMultipleSteps(
|
|
690
|
+
const { pendingStepId } = await findPendingStepAwaitingMultipleSteps(
|
|
705
691
|
_izContext,
|
|
706
|
-
createAwaitingStepId(
|
|
707
|
-
parentFlowId,
|
|
708
|
-
prefix
|
|
709
|
-
)
|
|
692
|
+
createAwaitingStepId(parentFlowId, prefix)
|
|
710
693
|
);
|
|
711
694
|
|
|
712
695
|
if (!pendingStepId) {
|
|
713
696
|
_izContext.logger.warn(
|
|
714
|
-
`No pending step found for awaitingStepId: ${
|
|
697
|
+
`No pending step found for awaitingStepId: ${parentFlowId}`
|
|
715
698
|
);
|
|
716
699
|
return { returnValue, errorsFound };
|
|
717
700
|
}
|
|
@@ -721,14 +704,11 @@ export async function completeAction(
|
|
|
721
704
|
collectedReturnValueByAwaitingStepId,
|
|
722
705
|
collectedErrors,
|
|
723
706
|
returnValues,
|
|
724
|
-
additionalAttributes
|
|
707
|
+
additionalAttributes
|
|
725
708
|
} = await checkAllAwaitingStepsFinishedWithReturnParams(
|
|
726
709
|
_izContext,
|
|
727
710
|
pendingStepId,
|
|
728
|
-
createAwaitingStepId(
|
|
729
|
-
parentFlowId,
|
|
730
|
-
prefix
|
|
731
|
-
),
|
|
711
|
+
createAwaitingStepId(parentFlowId, prefix),
|
|
732
712
|
errorsFound,
|
|
733
713
|
returnValue,
|
|
734
714
|
{ checkIsAllError: settings.checkIsAllError }
|
|
@@ -746,24 +726,24 @@ export async function completeAction(
|
|
|
746
726
|
|
|
747
727
|
if (status) {
|
|
748
728
|
await Promise.all(
|
|
749
|
-
(additionalAttributes
|
|
729
|
+
(additionalAttributes?.listOfRecords ?? []).flatMap(records =>
|
|
750
730
|
Object.values(records).map(async record =>
|
|
751
731
|
dynamodbSharedLib.updateItem(
|
|
752
732
|
_izContext,
|
|
753
733
|
await dynamodbSharedLib.tableName(
|
|
754
734
|
_izContext,
|
|
755
735
|
record.tableName,
|
|
756
|
-
record.serviceTag
|
|
736
|
+
record.serviceTag
|
|
757
737
|
),
|
|
758
738
|
{
|
|
759
|
-
...record.objInstanceFull.identifiers
|
|
739
|
+
...record.objInstanceFull.identifiers
|
|
760
740
|
},
|
|
761
741
|
{
|
|
762
|
-
...record.objInstanceFull.fields
|
|
742
|
+
...record.objInstanceFull.fields
|
|
763
743
|
}
|
|
764
|
-
)
|
|
765
|
-
)
|
|
766
|
-
)
|
|
744
|
+
)
|
|
745
|
+
)
|
|
746
|
+
)
|
|
767
747
|
);
|
|
768
748
|
}
|
|
769
749
|
|
|
@@ -779,3 +759,16 @@ export async function completeAction(
|
|
|
779
759
|
_izContext.logger.error(err);
|
|
780
760
|
}
|
|
781
761
|
}
|
|
762
|
+
|
|
763
|
+
export {
|
|
764
|
+
createAwaitingMultipleSteps,
|
|
765
|
+
updateAwaitingMultipleStep,
|
|
766
|
+
findPendingStepAwaitingMultipleSteps,
|
|
767
|
+
findPendingStepsAwaitingMultipleSteps,
|
|
768
|
+
findPendingStepIdAwaitingMultipleSteps,
|
|
769
|
+
findAwaitingMultipleStepByPending,
|
|
770
|
+
checkAllAwaitingStepsFinishedWithReturnParams,
|
|
771
|
+
clearAllAwaitingSteps,
|
|
772
|
+
removeAwaitingMultipleStep,
|
|
773
|
+
completeAction
|
|
774
|
+
};
|
package/src/awaitingStep.js
CHANGED
|
@@ -14,28 +14,28 @@ You should have received a copy of the GNU Affero General Public License
|
|
|
14
14
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import { NoRetryError } from
|
|
18
|
-
import dynamodbSharedLib from
|
|
17
|
+
import { NoRetryError } from '@izara_project/izara-core-library-core';
|
|
18
|
+
import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
|
|
19
19
|
|
|
20
|
-
import { createFieldNameUniqueRequestId } from
|
|
20
|
+
import { createFieldNameUniqueRequestId } from './asyncFlowSharedLib.js';
|
|
21
21
|
|
|
22
22
|
async function _findSinglePendingStep(_izContext, awaitingStepId) {
|
|
23
|
-
_izContext.logger.debug(
|
|
24
|
-
awaitingStepId
|
|
23
|
+
_izContext.logger.debug('[Lib:AsyncFlow:findSinglePendingStep] Input', {
|
|
24
|
+
awaitingStepId
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
if (!awaitingStepId) {
|
|
28
|
-
throw new NoRetryError(
|
|
28
|
+
throw new NoRetryError('awaitingStepId is required');
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
const { Items } = await dynamodbSharedLib.query(
|
|
32
32
|
_izContext,
|
|
33
|
-
dynamodbSharedLib.tableName(_izContext,
|
|
34
|
-
{ awaitingStepId }
|
|
33
|
+
dynamodbSharedLib.tableName(_izContext, 'AwaitingStep'),
|
|
34
|
+
{ awaitingStepId }
|
|
35
35
|
);
|
|
36
36
|
|
|
37
37
|
if (Items.length !== 1) {
|
|
38
|
-
throw new NoRetryError(
|
|
38
|
+
throw new NoRetryError('listPendingSteps not equals 1');
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
return Items[0];
|
|
@@ -59,18 +59,18 @@ async function _findSinglePendingStep(_izContext, awaitingStepId) {
|
|
|
59
59
|
* @param {object} [callingFlowConfig={}] - Calling flow configuration.
|
|
60
60
|
* @returns {Promise<void>}
|
|
61
61
|
*/
|
|
62
|
-
|
|
62
|
+
async function createAwaitingStep(
|
|
63
63
|
_izContext,
|
|
64
64
|
awaitingStepId,
|
|
65
65
|
pendingStepId,
|
|
66
66
|
additionalAttributes = {},
|
|
67
|
-
callingFlowConfig = {}
|
|
67
|
+
callingFlowConfig = {}
|
|
68
68
|
) {
|
|
69
|
-
_izContext.logger.debug(
|
|
69
|
+
_izContext.logger.debug('[Lib:AsyncFlow:createAwaitingStep] Input', {
|
|
70
70
|
awaitingStepId,
|
|
71
71
|
pendingStepId,
|
|
72
72
|
additionalAttributes,
|
|
73
|
-
callingFlowConfig
|
|
73
|
+
callingFlowConfig
|
|
74
74
|
});
|
|
75
75
|
|
|
76
76
|
const attributesWhenCreate = {
|
|
@@ -78,7 +78,7 @@ export async function createAwaitingStep(
|
|
|
78
78
|
pendingStepId,
|
|
79
79
|
timestamp: Date.now(),
|
|
80
80
|
uniqueRequestId: _izContext.uniqueRequestId,
|
|
81
|
-
...additionalAttributes
|
|
81
|
+
...additionalAttributes
|
|
82
82
|
};
|
|
83
83
|
|
|
84
84
|
if (Object.keys(callingFlowConfig).length > 0) {
|
|
@@ -87,8 +87,8 @@ export async function createAwaitingStep(
|
|
|
87
87
|
|
|
88
88
|
await dynamodbSharedLib.putItem(
|
|
89
89
|
_izContext,
|
|
90
|
-
dynamodbSharedLib.tableName(_izContext,
|
|
91
|
-
attributesWhenCreate
|
|
90
|
+
dynamodbSharedLib.tableName(_izContext, 'AwaitingStep'),
|
|
91
|
+
attributesWhenCreate
|
|
92
92
|
);
|
|
93
93
|
}
|
|
94
94
|
|
|
@@ -100,7 +100,7 @@ export async function createAwaitingStep(
|
|
|
100
100
|
* @returns {Promise<object>} The found pending step record.
|
|
101
101
|
* @throws {NoRetryError} If missing or if not exactly one record found.
|
|
102
102
|
*/
|
|
103
|
-
|
|
103
|
+
async function findPendingStep(_izContext, awaitingStepId) {
|
|
104
104
|
return _findSinglePendingStep(_izContext, awaitingStepId);
|
|
105
105
|
}
|
|
106
106
|
|
|
@@ -113,24 +113,20 @@ export async function findPendingStep(_izContext, awaitingStepId) {
|
|
|
113
113
|
* @returns {Promise<void>}
|
|
114
114
|
* @throws {NoRetryError} If awaitingStepId or pendingStepId is missing.
|
|
115
115
|
*/
|
|
116
|
-
|
|
117
|
-
_izContext,
|
|
118
|
-
awaitingStepId,
|
|
119
|
-
pendingStepId,
|
|
120
|
-
) {
|
|
121
|
-
_izContext.logger.debug("[Lib:AsyncFlow:removeAwaitingStep] Input", {
|
|
116
|
+
async function removeAwaitingStep(_izContext, awaitingStepId, pendingStepId) {
|
|
117
|
+
_izContext.logger.debug('[Lib:AsyncFlow:removeAwaitingStep] Input', {
|
|
122
118
|
awaitingStepId,
|
|
123
|
-
pendingStepId
|
|
119
|
+
pendingStepId
|
|
124
120
|
});
|
|
125
121
|
|
|
126
122
|
if (!awaitingStepId || !pendingStepId) {
|
|
127
|
-
throw new NoRetryError(
|
|
123
|
+
throw new NoRetryError('awaitingStepId, pendingStepId required');
|
|
128
124
|
}
|
|
129
125
|
|
|
130
126
|
await dynamodbSharedLib.deleteItem(
|
|
131
127
|
_izContext,
|
|
132
|
-
dynamodbSharedLib.tableName(_izContext,
|
|
133
|
-
{ awaitingStepId, pendingStepId }
|
|
128
|
+
dynamodbSharedLib.tableName(_izContext, 'AwaitingStep'),
|
|
129
|
+
{ awaitingStepId, pendingStepId }
|
|
134
130
|
);
|
|
135
131
|
}
|
|
136
132
|
|
|
@@ -145,21 +141,21 @@ export async function removeAwaitingStep(
|
|
|
145
141
|
* @returns {Promise<void>}
|
|
146
142
|
* @throws {NoRetryError} If required arguments are missing.
|
|
147
143
|
*/
|
|
148
|
-
|
|
144
|
+
async function removeAwaitingStepWithCheckUniqueRequestId(
|
|
149
145
|
_izContext,
|
|
150
146
|
awaitingStepId,
|
|
151
147
|
pendingStepId,
|
|
152
148
|
checkUniqueRequestId,
|
|
153
|
-
prefix =
|
|
149
|
+
prefix = ''
|
|
154
150
|
) {
|
|
155
151
|
_izContext.logger.debug(
|
|
156
|
-
|
|
157
|
-
{ awaitingStepId, pendingStepId, checkUniqueRequestId, prefix }
|
|
152
|
+
'[Lib:AsyncFlow:removeAwaitingStepWithCheckUniqueRequestId] Input',
|
|
153
|
+
{ awaitingStepId, pendingStepId, checkUniqueRequestId, prefix }
|
|
158
154
|
);
|
|
159
155
|
|
|
160
156
|
if (!awaitingStepId || !pendingStepId || !checkUniqueRequestId) {
|
|
161
157
|
throw new NoRetryError(
|
|
162
|
-
|
|
158
|
+
'awaitingStepId, pendingStepId, checkUniqueRequestId required'
|
|
163
159
|
);
|
|
164
160
|
}
|
|
165
161
|
|
|
@@ -167,19 +163,26 @@ export async function removeAwaitingStepWithCheckUniqueRequestId(
|
|
|
167
163
|
additionalAttributes: { checkUniqueRequestId },
|
|
168
164
|
logicalElements: [
|
|
169
165
|
{
|
|
170
|
-
type:
|
|
171
|
-
comparison:
|
|
166
|
+
type: 'logical',
|
|
167
|
+
comparison: 'equals',
|
|
172
168
|
lhsAttribute: createFieldNameUniqueRequestId(prefix),
|
|
173
|
-
rhsReference:
|
|
174
|
-
}
|
|
175
|
-
]
|
|
169
|
+
rhsReference: 'checkUniqueRequestId'
|
|
170
|
+
}
|
|
171
|
+
]
|
|
176
172
|
};
|
|
177
173
|
|
|
178
174
|
await dynamodbSharedLib.deleteItem(
|
|
179
175
|
_izContext,
|
|
180
|
-
dynamodbSharedLib.tableName(_izContext,
|
|
176
|
+
dynamodbSharedLib.tableName(_izContext, 'AwaitingStep'),
|
|
181
177
|
{ awaitingStepId, pendingStepId },
|
|
182
178
|
queryElementsCondition,
|
|
183
|
-
{ errorOnConditionalExpNotPass: false }
|
|
179
|
+
{ errorOnConditionalExpNotPass: false }
|
|
184
180
|
);
|
|
185
181
|
}
|
|
182
|
+
|
|
183
|
+
export {
|
|
184
|
+
createAwaitingStep,
|
|
185
|
+
findPendingStep,
|
|
186
|
+
removeAwaitingStep,
|
|
187
|
+
removeAwaitingStepWithCheckUniqueRequestId
|
|
188
|
+
};
|