@izara_project/izara-core-library-asynchronous-flow 1.0.49 → 1.0.50
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 +7 -2
- package/index.js +4 -4
- package/package.json +1 -1
- package/src/asyncFlowSharedLib.js +94 -101
- package/src/awaitingMultipleSteps.js +118 -96
- package/src/awaitingStep.js +32 -32
package/README.md
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
# izara-core-library-asynchronous-flow
|
|
2
2
|
|
|
3
3
|
# update version
|
|
4
|
+
|
|
4
5
|
- commit code first
|
|
5
|
-
npm version patch || npm version minor || npm version major
|
|
6
|
+
npm version patch || npm version minor || npm version major
|
|
6
7
|
|
|
7
8
|
# can also push to repo ..
|
|
9
|
+
|
|
8
10
|
git push
|
|
11
|
+
|
|
9
12
|
# make sure commits look correct
|
|
10
13
|
|
|
11
14
|
# push to npm
|
|
15
|
+
|
|
12
16
|
npm publish
|
|
13
17
|
|
|
14
18
|
# update project that uses this package
|
|
15
|
-
|
|
19
|
+
|
|
20
|
+
npm update @izara_project/izara-core-library-asynchronous-flow
|
package/index.js
CHANGED
|
@@ -15,12 +15,12 @@ You should have received a copy of the GNU Affero General Public License
|
|
|
15
15
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
import * as asyncFlowSharedLib from
|
|
19
|
-
import * as awaitingStep from
|
|
20
|
-
import * as awaitingMultipleSteps from
|
|
18
|
+
import * as asyncFlowSharedLib from "./src/asyncFlowSharedLib.js";
|
|
19
|
+
import * as awaitingStep from "./src/awaitingStep.js";
|
|
20
|
+
import * as awaitingMultipleSteps from "./src/awaitingMultipleSteps.js";
|
|
21
21
|
|
|
22
22
|
export default {
|
|
23
23
|
...asyncFlowSharedLib,
|
|
24
24
|
...awaitingStep,
|
|
25
|
-
...awaitingMultipleSteps
|
|
25
|
+
...awaitingMultipleSteps,
|
|
26
26
|
};
|
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.50",
|
|
7
7
|
"description": "Shared asynchronous flow logic",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"main": "index.js",
|
|
@@ -16,17 +16,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
// Core libraries
|
|
19
|
-
import { NoRetryError } from
|
|
20
|
-
import Logger from
|
|
19
|
+
import { NoRetryError } from "@izara_project/izara-core-library-core";
|
|
20
|
+
import Logger from "@izara_project/izara-core-library-logger";
|
|
21
21
|
|
|
22
22
|
// Data and service interaction libraries
|
|
23
|
-
import dynamodbSharedLib from
|
|
24
|
-
import sqsSharedLib from
|
|
23
|
+
import dynamodbSharedLib from "@izara_project/izara-core-library-dynamodb";
|
|
24
|
+
import sqsSharedLib from "@izara_project/izara-core-library-sqs";
|
|
25
25
|
|
|
26
26
|
// External service interactions
|
|
27
|
-
import { sqs } from
|
|
27
|
+
import { sqs } from "@izara_project/izara-core-library-external-request";
|
|
28
28
|
|
|
29
|
-
import { identifierUuid } from
|
|
29
|
+
import { identifierUuid } from "@izara_project/izara-shared-core";
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
32
|
* Helper to safely join a prefix and an ID with a single underscore.
|
|
@@ -35,18 +35,18 @@ import { identifierUuid } from '@izara_project/izara-shared-core';
|
|
|
35
35
|
* @param {string} [prefix='']
|
|
36
36
|
* @returns {string}
|
|
37
37
|
*/
|
|
38
|
-
function _joinPrefixAndId(id, prefix =
|
|
38
|
+
function _joinPrefixAndId(id, prefix = "") {
|
|
39
39
|
if (!prefix) {
|
|
40
40
|
return id;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
let cleanPrefix = prefix;
|
|
44
|
-
if (prefix.endsWith(
|
|
44
|
+
if (prefix.endsWith("_")) {
|
|
45
45
|
cleanPrefix = prefix.slice(0, -1);
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
let cleanId = id;
|
|
49
|
-
if (id.startsWith(
|
|
49
|
+
if (id.startsWith("_")) {
|
|
50
50
|
cleanId = id.slice(1);
|
|
51
51
|
}
|
|
52
52
|
|
|
@@ -59,7 +59,7 @@ function _joinPrefixAndId(id, prefix = '') {
|
|
|
59
59
|
* @param {string} [prefix='']
|
|
60
60
|
* @returns {string}
|
|
61
61
|
*/
|
|
62
|
-
function createAwaitingStepId(partitionKey, prefix =
|
|
62
|
+
function createAwaitingStepId(partitionKey, prefix = "") {
|
|
63
63
|
return _joinPrefixAndId(partitionKey, prefix);
|
|
64
64
|
}
|
|
65
65
|
|
|
@@ -69,7 +69,7 @@ function createAwaitingStepId(partitionKey, prefix = '') {
|
|
|
69
69
|
* @param {string} [prefix='']
|
|
70
70
|
* @returns {string}
|
|
71
71
|
*/
|
|
72
|
-
function createPendingStepId(identifierId, prefix =
|
|
72
|
+
function createPendingStepId(identifierId, prefix = "") {
|
|
73
73
|
return _joinPrefixAndId(identifierId, prefix);
|
|
74
74
|
}
|
|
75
75
|
|
|
@@ -81,7 +81,7 @@ function createPendingStepId(identifierId, prefix = '') {
|
|
|
81
81
|
*/
|
|
82
82
|
function createFieldNameUniqueRequestId(
|
|
83
83
|
prefix,
|
|
84
|
-
uniqueRequestIdFieldName =
|
|
84
|
+
uniqueRequestIdFieldName = "UniqueRequestId",
|
|
85
85
|
) {
|
|
86
86
|
return prefix + uniqueRequestIdFieldName;
|
|
87
87
|
}
|
|
@@ -93,8 +93,8 @@ function createFieldNameUniqueRequestId(
|
|
|
93
93
|
* @param {string} [prefix=""]
|
|
94
94
|
* @returns {string}
|
|
95
95
|
*/
|
|
96
|
-
function createConcatenatedAwaitingStepId(partitionKey, sortId, prefix =
|
|
97
|
-
return prefix + partitionKey +
|
|
96
|
+
function createConcatenatedAwaitingStepId(partitionKey, sortId, prefix = "") {
|
|
97
|
+
return prefix + partitionKey + "_" + sortId;
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
/**
|
|
@@ -104,7 +104,7 @@ function createConcatenatedAwaitingStepId(partitionKey, sortId, prefix = '') {
|
|
|
104
104
|
* @returns {string}
|
|
105
105
|
*/
|
|
106
106
|
function createConcatenatedPendingStepId(parentId, childId) {
|
|
107
|
-
return parentId +
|
|
107
|
+
return parentId + "_" + childId;
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
/**
|
|
@@ -113,7 +113,7 @@ function createConcatenatedPendingStepId(parentId, childId) {
|
|
|
113
113
|
* @param {string} [prefix=''] - The prefix to prepend to the parent Ids.
|
|
114
114
|
* @returns {string} The parent Flow Id created.
|
|
115
115
|
*/
|
|
116
|
-
function createParentFlowId(prefix =
|
|
116
|
+
function createParentFlowId(prefix = "") {
|
|
117
117
|
return _joinPrefixAndId(identifierUuid(), prefix);
|
|
118
118
|
}
|
|
119
119
|
|
|
@@ -124,9 +124,9 @@ function createParentFlowId(prefix = '') {
|
|
|
124
124
|
* @returns {string}
|
|
125
125
|
* @throws {NoRetryError} If stripped value equals prefix (invalid)
|
|
126
126
|
*/
|
|
127
|
-
function explodePendingStepId(pendingStepId, prefix =
|
|
127
|
+
function explodePendingStepId(pendingStepId, prefix = "") {
|
|
128
128
|
if (!pendingStepId) {
|
|
129
|
-
throw new NoRetryError(
|
|
129
|
+
throw new NoRetryError("pendingStepId is required");
|
|
130
130
|
}
|
|
131
131
|
if (!prefix) {
|
|
132
132
|
return pendingStepId;
|
|
@@ -134,10 +134,10 @@ function explodePendingStepId(pendingStepId, prefix = '') {
|
|
|
134
134
|
|
|
135
135
|
const identifierId = pendingStepId.slice(prefix.length + 1);
|
|
136
136
|
if (identifierId === prefix) {
|
|
137
|
-
throw new NoRetryError(
|
|
137
|
+
throw new NoRetryError("IdentifierId should not be like prefix.");
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
-
Logger.debug(
|
|
140
|
+
Logger.debug("return explode:", { identifierId });
|
|
141
141
|
return identifierId;
|
|
142
142
|
}
|
|
143
143
|
|
|
@@ -177,29 +177,29 @@ async function checkUniqueRequestProcessing(
|
|
|
177
177
|
_izContext,
|
|
178
178
|
tableName,
|
|
179
179
|
primaryKey,
|
|
180
|
-
prefix =
|
|
180
|
+
prefix = "",
|
|
181
181
|
overwriteUniqueRequestId = null,
|
|
182
|
-
uniqueRequestIdFieldName =
|
|
182
|
+
uniqueRequestIdFieldName = "UniqueRequestId", // if set will check/add this fieldname with _izContext.uniqueRequestId value
|
|
183
183
|
) {
|
|
184
184
|
_izContext.logger.debug(
|
|
185
|
-
|
|
185
|
+
"[Lib:AsyncFlow:checkUniqueRequestProcessing] Input:",
|
|
186
186
|
{
|
|
187
187
|
_izContext,
|
|
188
188
|
tableName,
|
|
189
189
|
primaryKey,
|
|
190
190
|
prefix,
|
|
191
191
|
overwriteUniqueRequestId,
|
|
192
|
-
uniqueRequestIdFieldName
|
|
193
|
-
}
|
|
192
|
+
uniqueRequestIdFieldName,
|
|
193
|
+
},
|
|
194
194
|
);
|
|
195
195
|
|
|
196
196
|
if (!tableName || !primaryKey) {
|
|
197
|
-
throw new NoRetryError(
|
|
197
|
+
throw new NoRetryError("tableName and primaryKey are required");
|
|
198
198
|
}
|
|
199
199
|
|
|
200
200
|
try {
|
|
201
|
-
_izContext.logger.debug(
|
|
202
|
-
uniqueRequestId: _izContext.uniqueRequestId
|
|
201
|
+
_izContext.logger.debug("[Lib:checkUniqueRequestProcessing] reqId", {
|
|
202
|
+
uniqueRequestId: _izContext.uniqueRequestId,
|
|
203
203
|
});
|
|
204
204
|
|
|
205
205
|
let uniqueRequestId = overwriteUniqueRequestId;
|
|
@@ -209,26 +209,26 @@ async function checkUniqueRequestProcessing(
|
|
|
209
209
|
|
|
210
210
|
uniqueRequestIdFieldName = createFieldNameUniqueRequestId(
|
|
211
211
|
prefix,
|
|
212
|
-
uniqueRequestIdFieldName
|
|
212
|
+
uniqueRequestIdFieldName,
|
|
213
213
|
);
|
|
214
214
|
|
|
215
215
|
for (let i = 0; i < 2; i++) {
|
|
216
216
|
const existingRecord = await dynamodbSharedLib.getItem(
|
|
217
217
|
_izContext,
|
|
218
218
|
dynamodbSharedLib.tableName(_izContext, tableName),
|
|
219
|
-
primaryKey
|
|
219
|
+
primaryKey,
|
|
220
220
|
);
|
|
221
221
|
|
|
222
222
|
if (!existingRecord) {
|
|
223
|
-
return [
|
|
223
|
+
return ["recordNotFound", {}];
|
|
224
224
|
}
|
|
225
225
|
|
|
226
226
|
const currentReqId = existingRecord[uniqueRequestIdFieldName];
|
|
227
227
|
if (currentReqId === uniqueRequestId) {
|
|
228
|
-
return [
|
|
228
|
+
return ["process", existingRecord];
|
|
229
229
|
}
|
|
230
230
|
if (currentReqId) {
|
|
231
|
-
return [
|
|
231
|
+
return ["stop", existingRecord];
|
|
232
232
|
}
|
|
233
233
|
|
|
234
234
|
try {
|
|
@@ -239,25 +239,25 @@ async function checkUniqueRequestProcessing(
|
|
|
239
239
|
[
|
|
240
240
|
{
|
|
241
241
|
attributeName: uniqueRequestIdFieldName,
|
|
242
|
-
action:
|
|
243
|
-
value: _izContext.uniqueRequestId
|
|
244
|
-
}
|
|
242
|
+
action: "set",
|
|
243
|
+
value: _izContext.uniqueRequestId,
|
|
244
|
+
},
|
|
245
245
|
],
|
|
246
246
|
{
|
|
247
247
|
logicalElements: [
|
|
248
248
|
{
|
|
249
|
-
type:
|
|
250
|
-
function:
|
|
251
|
-
attribute: uniqueRequestIdFieldName
|
|
252
|
-
}
|
|
249
|
+
type: "function",
|
|
250
|
+
function: "attribute_not_exists",
|
|
251
|
+
attribute: uniqueRequestIdFieldName,
|
|
252
|
+
},
|
|
253
253
|
],
|
|
254
|
-
returnValues:
|
|
254
|
+
returnValues: "ALL_NEW",
|
|
255
255
|
},
|
|
256
|
-
{ complexAttributes: true }
|
|
256
|
+
{ complexAttributes: true },
|
|
257
257
|
);
|
|
258
|
-
return [
|
|
258
|
+
return ["process", updateRecord];
|
|
259
259
|
} catch (err) {
|
|
260
|
-
if (err.name ===
|
|
260
|
+
if (err.name === "ConditionalCheckFailedException") {
|
|
261
261
|
continue;
|
|
262
262
|
}
|
|
263
263
|
throw err;
|
|
@@ -266,13 +266,12 @@ async function checkUniqueRequestProcessing(
|
|
|
266
266
|
|
|
267
267
|
throw new NoRetryError(
|
|
268
268
|
`unable to set uniqueRequestId in table ${tableName}`,
|
|
269
|
-
{ primaryKey }
|
|
269
|
+
{ primaryKey },
|
|
270
270
|
);
|
|
271
271
|
} catch (err) {
|
|
272
|
-
_izContext.logger.error(
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
);
|
|
272
|
+
_izContext.logger.error("[Lib:checkUniqueRequestProcessing] Error", {
|
|
273
|
+
err,
|
|
274
|
+
});
|
|
276
275
|
throw err;
|
|
277
276
|
}
|
|
278
277
|
}
|
|
@@ -294,31 +293,30 @@ async function checkTimeCacheComplete(
|
|
|
294
293
|
fullMainTableName,
|
|
295
294
|
keyValues,
|
|
296
295
|
timeCacheComplete,
|
|
297
|
-
prefix
|
|
296
|
+
prefix,
|
|
298
297
|
) {
|
|
299
|
-
_izContext.logger.debug(
|
|
298
|
+
_izContext.logger.debug("[Lib:AsyncFlow:checkTimeCacheComplete] Input:", {
|
|
300
299
|
_izContext,
|
|
301
300
|
fullMainTableName,
|
|
302
301
|
keyValues,
|
|
303
302
|
timeCacheComplete,
|
|
304
|
-
prefix
|
|
303
|
+
prefix,
|
|
305
304
|
});
|
|
306
305
|
|
|
307
306
|
if (!fullMainTableName || !keyValues || !timeCacheComplete || !prefix) {
|
|
308
307
|
throw new NoRetryError(
|
|
309
|
-
|
|
310
|
-
|
|
308
|
+
"fullMainTableName, keyValues, timeCacheComplete" +
|
|
309
|
+
" and prefix are required",
|
|
311
310
|
);
|
|
312
311
|
}
|
|
313
312
|
|
|
314
|
-
const [returnValue, , uniqueRequestId] =
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
);
|
|
313
|
+
const [returnValue, , uniqueRequestId] = await checkAndGetTimeCacheComplete(
|
|
314
|
+
_izContext,
|
|
315
|
+
fullMainTableName,
|
|
316
|
+
keyValues,
|
|
317
|
+
timeCacheComplete,
|
|
318
|
+
prefix,
|
|
319
|
+
);
|
|
322
320
|
return [returnValue, uniqueRequestId];
|
|
323
321
|
}
|
|
324
322
|
|
|
@@ -340,34 +338,34 @@ async function checkAndGetTimeCacheComplete(
|
|
|
340
338
|
fullMainTableName,
|
|
341
339
|
keyValues,
|
|
342
340
|
timeCacheComplete,
|
|
343
|
-
prefix
|
|
341
|
+
prefix,
|
|
344
342
|
) {
|
|
345
343
|
_izContext.logger.debug(
|
|
346
|
-
|
|
344
|
+
"[Lib:AsyncFlow:checkAndGetTimeCacheComplete] Input:",
|
|
347
345
|
{
|
|
348
346
|
fullMainTableName,
|
|
349
347
|
keyValues,
|
|
350
348
|
timeCacheComplete,
|
|
351
|
-
prefix
|
|
352
|
-
}
|
|
349
|
+
prefix,
|
|
350
|
+
},
|
|
353
351
|
);
|
|
354
352
|
|
|
355
|
-
const uniqueRequestIdFieldName = createFieldNameUniqueRequestId(
|
|
356
|
-
const cacheCompleteFieldName = prefix +
|
|
353
|
+
const uniqueRequestIdFieldName = createFieldNameUniqueRequestId("cache");
|
|
354
|
+
const cacheCompleteFieldName = prefix + "CacheComplete";
|
|
357
355
|
|
|
358
356
|
const getTimeCacheComplete = await dynamodbSharedLib.getItem(
|
|
359
357
|
_izContext,
|
|
360
358
|
fullMainTableName,
|
|
361
|
-
keyValues
|
|
359
|
+
keyValues,
|
|
362
360
|
);
|
|
363
361
|
_izContext.logger.debug(
|
|
364
362
|
`[Lib:checkAndGetTimeCacheComplete] ${fullMainTableName}`,
|
|
365
|
-
{ getTimeCacheComplete }
|
|
363
|
+
{ getTimeCacheComplete },
|
|
366
364
|
);
|
|
367
365
|
|
|
368
366
|
if (!getTimeCacheComplete) {
|
|
369
367
|
throw new NoRetryError(
|
|
370
|
-
`cannot getTimeCacheComplete from ${fullMainTableName}
|
|
368
|
+
`cannot getTimeCacheComplete from ${fullMainTableName}`,
|
|
371
369
|
);
|
|
372
370
|
}
|
|
373
371
|
|
|
@@ -393,7 +391,7 @@ async function checkAndGetTimeCacheComplete(
|
|
|
393
391
|
return [
|
|
394
392
|
true,
|
|
395
393
|
getTimeCacheComplete[cacheCompleteFieldName],
|
|
396
|
-
getTimeCacheComplete[uniqueRequestIdFieldName]
|
|
394
|
+
getTimeCacheComplete[uniqueRequestIdFieldName],
|
|
397
395
|
];
|
|
398
396
|
}
|
|
399
397
|
|
|
@@ -413,20 +411,18 @@ async function checkCacheUniqueRequestId(
|
|
|
413
411
|
fullMainTableName,
|
|
414
412
|
keyValues,
|
|
415
413
|
checkUniqueRequestId,
|
|
416
|
-
uniqueRequestIdCompleteFieldName
|
|
414
|
+
uniqueRequestIdCompleteFieldName,
|
|
417
415
|
) {
|
|
418
416
|
const cacheObject = await dynamodbSharedLib.getItem(
|
|
419
417
|
_izContext,
|
|
420
418
|
fullMainTableName,
|
|
421
|
-
keyValues
|
|
419
|
+
keyValues,
|
|
422
420
|
);
|
|
423
|
-
_izContext.logger.debug(
|
|
424
|
-
cacheObject
|
|
421
|
+
_izContext.logger.debug("[Lib:checkCacheUniqueRequestId] Output", {
|
|
422
|
+
cacheObject,
|
|
425
423
|
});
|
|
426
424
|
|
|
427
|
-
return
|
|
428
|
-
cacheObject[uniqueRequestIdCompleteFieldName] === checkUniqueRequestId
|
|
429
|
-
);
|
|
425
|
+
return cacheObject[uniqueRequestIdCompleteFieldName] === checkUniqueRequestId;
|
|
430
426
|
}
|
|
431
427
|
|
|
432
428
|
//====================================== end Multiple Lambda Invocations (Logic pagination of handling results)
|
|
@@ -446,12 +442,12 @@ function validateStartKeyParam(
|
|
|
446
442
|
_izContext,
|
|
447
443
|
startKey,
|
|
448
444
|
partitionKeyFieldName,
|
|
449
|
-
sortKeyFieldName
|
|
445
|
+
sortKeyFieldName,
|
|
450
446
|
) {
|
|
451
|
-
_izContext.logger.debug(
|
|
447
|
+
_izContext.logger.debug("[Lib:AsyncFlow:validateStartKeyParam] Input:", {
|
|
452
448
|
startKey,
|
|
453
449
|
partitionKeyFieldName,
|
|
454
|
-
sortKeyFieldName
|
|
450
|
+
sortKeyFieldName,
|
|
455
451
|
});
|
|
456
452
|
|
|
457
453
|
const stringNotEmptyRegex = /^[A-Za-z0-9_-]+$/;
|
|
@@ -463,16 +459,16 @@ function validateStartKeyParam(
|
|
|
463
459
|
!stringNotEmptyRegex.test(sortKeyFieldName)
|
|
464
460
|
) {
|
|
465
461
|
throw new NoRetryError(
|
|
466
|
-
|
|
467
|
-
|
|
462
|
+
"validateStartKeyParam:" +
|
|
463
|
+
" Invalid partitionKeyFieldName or sortKeyFieldName",
|
|
468
464
|
);
|
|
469
465
|
}
|
|
470
466
|
|
|
471
467
|
if (startKey && Object.keys(startKey).length !== 0) {
|
|
472
468
|
if (!startKey[partitionKeyFieldName] || !startKey[sortKeyFieldName]) {
|
|
473
469
|
throw new NoRetryError(
|
|
474
|
-
|
|
475
|
-
|
|
470
|
+
"validateStartKeyParam: Invalid startKey," +
|
|
471
|
+
" missing partitionKeyFieldName or sortKeyFieldName",
|
|
476
472
|
);
|
|
477
473
|
}
|
|
478
474
|
return startKey;
|
|
@@ -499,48 +495,45 @@ async function validateMultipleInvocations(
|
|
|
499
495
|
messageProperty,
|
|
500
496
|
passOnStartKey = {},
|
|
501
497
|
numberInvocation,
|
|
502
|
-
queueName
|
|
498
|
+
queueName,
|
|
503
499
|
) {
|
|
504
500
|
_izContext.logger.debug(
|
|
505
|
-
|
|
501
|
+
"[Lib:AsyncFlow:validateMultipleInvocations] Input:",
|
|
506
502
|
{
|
|
507
503
|
messageProperty,
|
|
508
504
|
passOnStartKey,
|
|
509
505
|
numberInvocation,
|
|
510
|
-
queueName
|
|
511
|
-
}
|
|
506
|
+
queueName,
|
|
507
|
+
},
|
|
512
508
|
);
|
|
513
509
|
|
|
514
510
|
try {
|
|
515
511
|
const maxProcessInvocationCountImport = 20;
|
|
516
512
|
if (numberInvocation >= maxProcessInvocationCountImport) {
|
|
517
513
|
_izContext.logger.error(
|
|
518
|
-
|
|
514
|
+
"numberInvocation exceeds maxProcessInvocationCountImport limit",
|
|
519
515
|
);
|
|
520
516
|
throw new NoRetryError(
|
|
521
|
-
|
|
517
|
+
"numberInvocation exceeds maxProcessInvocationCountImport limit",
|
|
522
518
|
);
|
|
523
519
|
}
|
|
524
520
|
|
|
525
521
|
if (passOnStartKey) {
|
|
526
|
-
messageProperty[
|
|
522
|
+
messageProperty["startKey"] = passOnStartKey;
|
|
527
523
|
}
|
|
528
|
-
messageProperty[
|
|
524
|
+
messageProperty["numberInvocation"] = numberInvocation;
|
|
529
525
|
|
|
530
526
|
const messageReInvokeFunction = {
|
|
531
527
|
MessageBody: JSON.stringify(messageProperty),
|
|
532
|
-
QueueUrl: await sqsSharedLib.sqsQueueUrl(_izContext, queueName)
|
|
528
|
+
QueueUrl: await sqsSharedLib.sqsQueueUrl(_izContext, queueName),
|
|
533
529
|
};
|
|
534
530
|
_izContext.logger.debug(
|
|
535
531
|
`[Lib:validateMultipleInvocations] Send message to Dsq:${queueName}`,
|
|
536
|
-
{ messageReInvokeFunction }
|
|
532
|
+
{ messageReInvokeFunction },
|
|
537
533
|
);
|
|
538
534
|
await sqs.sendMessage(_izContext, messageReInvokeFunction);
|
|
539
535
|
} catch (err) {
|
|
540
|
-
_izContext.logger.error(
|
|
541
|
-
'[Lib:validateMultipleInvocations] Error',
|
|
542
|
-
{ err }
|
|
543
|
-
);
|
|
536
|
+
_izContext.logger.error("[Lib:validateMultipleInvocations] Error", { err });
|
|
544
537
|
throw err;
|
|
545
538
|
}
|
|
546
539
|
}
|
|
@@ -558,5 +551,5 @@ export {
|
|
|
558
551
|
checkAndGetTimeCacheComplete,
|
|
559
552
|
checkCacheUniqueRequestId,
|
|
560
553
|
validateStartKeyParam,
|
|
561
|
-
validateMultipleInvocations
|
|
554
|
+
validateMultipleInvocations,
|
|
562
555
|
};
|
|
@@ -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;
|
|
@@ -131,18 +131,18 @@ export 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(r => r.flowType);
|
|
145
|
+
const hasFlowPublish = flowType || records.some((r) => r.flowType);
|
|
146
146
|
|
|
147
147
|
let finalRecords = records;
|
|
148
148
|
|
|
@@ -150,13 +150,13 @@ export async function createAwaitingMultipleSteps(
|
|
|
150
150
|
finalRecords = [
|
|
151
151
|
{
|
|
152
152
|
awaitingStepId: createParentFlowId(prefix),
|
|
153
|
-
additionalAttributes
|
|
154
|
-
}
|
|
153
|
+
additionalAttributes,
|
|
154
|
+
},
|
|
155
155
|
];
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
if (hasFlowPublish) {
|
|
159
|
-
finalRecords = records.map(record => {
|
|
159
|
+
finalRecords = records.map((record) => {
|
|
160
160
|
const recordFlowType = record.flowType || flowType;
|
|
161
161
|
|
|
162
162
|
if (
|
|
@@ -165,7 +165,7 @@ export async function createAwaitingMultipleSteps(
|
|
|
165
165
|
!recordFlowType.serviceTag
|
|
166
166
|
) {
|
|
167
167
|
throw new NoRetryError(
|
|
168
|
-
|
|
168
|
+
"record.flowType must have both flowTag and serviceTag",
|
|
169
169
|
);
|
|
170
170
|
}
|
|
171
171
|
|
|
@@ -178,13 +178,13 @@ export async function createAwaitingMultipleSteps(
|
|
|
178
178
|
additionalAttributes: record.additionalAttributes,
|
|
179
179
|
message: {
|
|
180
180
|
...record.message,
|
|
181
|
-
parentFlowId: awaitingStepId
|
|
181
|
+
parentFlowId: awaitingStepId,
|
|
182
182
|
},
|
|
183
183
|
topicArn: snsSharedLib.snsTopicArnByFlowSchema(
|
|
184
184
|
_izContext,
|
|
185
185
|
recordFlowType.flowTag,
|
|
186
|
-
recordFlowType.serviceTag
|
|
187
|
-
)
|
|
186
|
+
recordFlowType.serviceTag,
|
|
187
|
+
),
|
|
188
188
|
};
|
|
189
189
|
});
|
|
190
190
|
}
|
|
@@ -204,7 +204,7 @@ export async function createAwaitingMultipleSteps(
|
|
|
204
204
|
awaitingStepId: createAwaitingStepId(awaitingStepId, prefix),
|
|
205
205
|
additionalAttributes: mergedAttributes
|
|
206
206
|
};
|
|
207
|
-
}
|
|
207
|
+
},
|
|
208
208
|
);
|
|
209
209
|
|
|
210
210
|
await _putAwaitingMultipleStepRecords(
|
|
@@ -213,8 +213,8 @@ export async function createAwaitingMultipleSteps(
|
|
|
213
213
|
finalPendingStepId,
|
|
214
214
|
{
|
|
215
215
|
complete: false,
|
|
216
|
-
errorsFound: []
|
|
217
|
-
}
|
|
216
|
+
errorsFound: [],
|
|
217
|
+
},
|
|
218
218
|
);
|
|
219
219
|
|
|
220
220
|
if (hasFlowPublish) {
|
|
@@ -222,9 +222,9 @@ export async function createAwaitingMultipleSteps(
|
|
|
222
222
|
finalRecords.map(async ({ message, topicArn }) => {
|
|
223
223
|
await sns.publishAsync(_izContext, {
|
|
224
224
|
TopicArn: `${topicArn}_In`,
|
|
225
|
-
Message: JSON.stringify(message)
|
|
225
|
+
Message: JSON.stringify(message),
|
|
226
226
|
});
|
|
227
|
-
})
|
|
227
|
+
}),
|
|
228
228
|
);
|
|
229
229
|
}
|
|
230
230
|
|
|
@@ -247,23 +247,23 @@ export async function updateAwaitingMultipleStep(
|
|
|
247
247
|
_izContext,
|
|
248
248
|
awaitingStepId,
|
|
249
249
|
pendingStepId,
|
|
250
|
-
data
|
|
250
|
+
data,
|
|
251
251
|
) {
|
|
252
252
|
const tableSteps = dynamodbSharedLib.tableName(
|
|
253
253
|
_izContext,
|
|
254
|
-
|
|
254
|
+
"AwaitingMultipleSteps",
|
|
255
255
|
);
|
|
256
256
|
|
|
257
257
|
await dynamodbSharedLib.updateItem(
|
|
258
258
|
_izContext,
|
|
259
259
|
tableSteps,
|
|
260
260
|
{ awaitingStepId, pendingStepId },
|
|
261
|
-
data
|
|
261
|
+
data,
|
|
262
262
|
);
|
|
263
263
|
|
|
264
|
-
_izContext.logger.debug(
|
|
264
|
+
_izContext.logger.debug("[Lib:updateAwaitingMultipleStep] Output", {
|
|
265
265
|
awaitingStepId,
|
|
266
|
-
data
|
|
266
|
+
data,
|
|
267
267
|
});
|
|
268
268
|
|
|
269
269
|
return { ...data, awaitingStepId };
|
|
@@ -278,15 +278,15 @@ export async function updateAwaitingMultipleStep(
|
|
|
278
278
|
*/
|
|
279
279
|
export async function findPendingStepAwaitingMultipleSteps(
|
|
280
280
|
_izContext,
|
|
281
|
-
awaitingStepId
|
|
281
|
+
awaitingStepId,
|
|
282
282
|
) {
|
|
283
|
-
_izContext.logger.debug(
|
|
284
|
-
awaitingStepId
|
|
283
|
+
_izContext.logger.debug("[Lib:findPendingStepAwaitingMultipleSteps] Input", {
|
|
284
|
+
awaitingStepId,
|
|
285
285
|
});
|
|
286
286
|
|
|
287
287
|
const items = await _queryPendingStepsByAwaitingStepId(
|
|
288
288
|
_izContext,
|
|
289
|
-
awaitingStepId
|
|
289
|
+
awaitingStepId,
|
|
290
290
|
);
|
|
291
291
|
|
|
292
292
|
if (items && items.length > 0) {
|
|
@@ -304,7 +304,7 @@ export async function findPendingStepAwaitingMultipleSteps(
|
|
|
304
304
|
*/
|
|
305
305
|
export async function findPendingStepsAwaitingMultipleSteps(
|
|
306
306
|
_izContext,
|
|
307
|
-
awaitingStepId
|
|
307
|
+
awaitingStepId,
|
|
308
308
|
) {
|
|
309
309
|
return _queryPendingStepsByAwaitingStepId(_izContext, awaitingStepId);
|
|
310
310
|
}
|
|
@@ -318,11 +318,11 @@ export async function findPendingStepsAwaitingMultipleSteps(
|
|
|
318
318
|
*/
|
|
319
319
|
export async function findPendingStepIdAwaitingMultipleSteps(
|
|
320
320
|
_izContext,
|
|
321
|
-
awaitingStepId
|
|
321
|
+
awaitingStepId,
|
|
322
322
|
) {
|
|
323
323
|
const items = await _queryPendingStepsByAwaitingStepId(
|
|
324
324
|
_izContext,
|
|
325
|
-
awaitingStepId
|
|
325
|
+
awaitingStepId,
|
|
326
326
|
);
|
|
327
327
|
if (items && items[0] && items[0].pendingStepId) {
|
|
328
328
|
return items[0].pendingStepId;
|
|
@@ -339,7 +339,7 @@ export async function findPendingStepIdAwaitingMultipleSteps(
|
|
|
339
339
|
*/
|
|
340
340
|
export async function findAwaitingMultipleStepByPending(
|
|
341
341
|
_izContext,
|
|
342
|
-
pendingStepId
|
|
342
|
+
pendingStepId,
|
|
343
343
|
) {
|
|
344
344
|
return _queryAwaitingStepsByPendingStepId(_izContext, pendingStepId);
|
|
345
345
|
}
|
|
@@ -362,16 +362,16 @@ export async function checkAllAwaitingStepsFinishedWithReturnParams(
|
|
|
362
362
|
currentAwaitingStepId,
|
|
363
363
|
errorsFound = [],
|
|
364
364
|
returnValues = {},
|
|
365
|
-
settings = { checkIsAllError: false }
|
|
365
|
+
settings = { checkIsAllError: false },
|
|
366
366
|
) {
|
|
367
367
|
_izContext.logger.debug(
|
|
368
|
-
|
|
368
|
+
"[Lib:checkAllAwaitingStepsFinishedWithReturnParams] Input parameters",
|
|
369
369
|
{
|
|
370
370
|
pendingStepId,
|
|
371
371
|
currentAwaitingStepId,
|
|
372
372
|
errorsFound,
|
|
373
|
-
returnValues
|
|
374
|
-
}
|
|
373
|
+
returnValues,
|
|
374
|
+
},
|
|
375
375
|
);
|
|
376
376
|
|
|
377
377
|
_assertPendingStepId(pendingStepId);
|
|
@@ -390,16 +390,26 @@ export async function checkAllAwaitingStepsFinishedWithReturnParams(
|
|
|
390
390
|
|
|
391
391
|
await dynamodbSharedLib.updateItem(
|
|
392
392
|
_izContext,
|
|
393
|
-
dynamodbSharedLib.tableName(_izContext,
|
|
393
|
+
dynamodbSharedLib.tableName(_izContext, "AwaitingMultipleStepByPending"),
|
|
394
394
|
{
|
|
395
395
|
pendingStepId,
|
|
396
|
-
awaitingStepId: currentAwaitingStepId
|
|
396
|
+
awaitingStepId: currentAwaitingStepId,
|
|
397
397
|
},
|
|
398
398
|
{
|
|
399
399
|
complete: true,
|
|
400
400
|
errorsFound,
|
|
401
|
-
returnValues
|
|
402
|
-
}
|
|
401
|
+
returnValues,
|
|
402
|
+
},
|
|
403
|
+
);
|
|
404
|
+
|
|
405
|
+
_izContext.logger.debug(
|
|
406
|
+
'[Lib:checkAllAwaitingStepsFinishedWithReturnParams] After updating awaitingStepItems',
|
|
407
|
+
{
|
|
408
|
+
pendingStepId,
|
|
409
|
+
awaitingStepId: currentAwaitingStepId,
|
|
410
|
+
errorsFound,
|
|
411
|
+
returnValues,
|
|
412
|
+
},
|
|
403
413
|
);
|
|
404
414
|
|
|
405
415
|
_izContext.logger.debug(
|
|
@@ -415,10 +425,12 @@ export async function checkAllAwaitingStepsFinishedWithReturnParams(
|
|
|
415
425
|
|
|
416
426
|
const awaitingStepItems = await _queryAwaitingStepsByPendingStepId(
|
|
417
427
|
_izContext,
|
|
418
|
-
pendingStepId
|
|
428
|
+
pendingStepId,
|
|
419
429
|
);
|
|
420
430
|
|
|
421
431
|
_izContext.logger.debug(
|
|
432
|
+
"[Lib:checkAllAwaitingStepsFinishedWithReturnParams] awaitingStepItems",
|
|
433
|
+
{ awaitingStepItems },
|
|
422
434
|
'[Lib:checkAllAwaitingStepsFinishedWithReturnParams] Queried awaitingStepItems',
|
|
423
435
|
{
|
|
424
436
|
pendingStepId,
|
|
@@ -444,7 +456,7 @@ export async function checkAllAwaitingStepsFinishedWithReturnParams(
|
|
|
444
456
|
}
|
|
445
457
|
|
|
446
458
|
const hasIncomplete = awaitingStepItems.some(
|
|
447
|
-
item => item.awaitingStepId !== currentAwaitingStepId && !item.complete
|
|
459
|
+
(item) => item.awaitingStepId !== currentAwaitingStepId && !item.complete,
|
|
448
460
|
);
|
|
449
461
|
|
|
450
462
|
let defaultAttrs = null;
|
|
@@ -515,7 +527,7 @@ export async function checkAllAwaitingStepsFinishedWithReturnParams(
|
|
|
515
527
|
collectedReturnValueByAwaitingStepId: null,
|
|
516
528
|
collectedErrors: [],
|
|
517
529
|
returnValues: null,
|
|
518
|
-
additionalAttributes: defaultAttrs
|
|
530
|
+
additionalAttributes: defaultAttrs,
|
|
519
531
|
};
|
|
520
532
|
}
|
|
521
533
|
|
|
@@ -539,7 +551,7 @@ export async function checkAllAwaitingStepsFinishedWithReturnParams(
|
|
|
539
551
|
if (item.errorsFound && item.errorsFound.length > 0) {
|
|
540
552
|
collectedErrors.push(
|
|
541
553
|
`Error found in step ${item.awaitingStepId}`,
|
|
542
|
-
...item.errorsFound
|
|
554
|
+
...item.errorsFound,
|
|
543
555
|
);
|
|
544
556
|
}
|
|
545
557
|
}
|
|
@@ -549,12 +561,12 @@ export async function checkAllAwaitingStepsFinishedWithReturnParams(
|
|
|
549
561
|
collectedReturnValueByAwaitingStepId,
|
|
550
562
|
collectedErrors,
|
|
551
563
|
returnValues: sharedReturnValues,
|
|
552
|
-
additionalAttributes: defaultAttrs
|
|
564
|
+
additionalAttributes: defaultAttrs,
|
|
553
565
|
};
|
|
554
566
|
|
|
555
567
|
if (settings.checkIsAllError) {
|
|
556
568
|
result.isAllError = awaitingStepItems.every(
|
|
557
|
-
item => item.errorsFound && item.errorsFound.length > 0
|
|
569
|
+
(item) => item.errorsFound && item.errorsFound.length > 0,
|
|
558
570
|
);
|
|
559
571
|
}
|
|
560
572
|
|
|
@@ -577,21 +589,21 @@ export async function checkAllAwaitingStepsFinishedWithReturnParams(
|
|
|
577
589
|
* @returns {Promise<boolean>} True if operations completed successfully.
|
|
578
590
|
*/
|
|
579
591
|
export async function clearAllAwaitingSteps(_izContext, pendingStepId) {
|
|
580
|
-
_izContext.logger.debug(
|
|
581
|
-
pendingStepId
|
|
592
|
+
_izContext.logger.debug("[Lib:clearAllAwaitingSteps] Input parameters", {
|
|
593
|
+
pendingStepId,
|
|
582
594
|
});
|
|
583
595
|
|
|
584
596
|
const awaitingStepItems = await _queryAwaitingStepsByPendingStepId(
|
|
585
597
|
_izContext,
|
|
586
|
-
pendingStepId
|
|
598
|
+
pendingStepId,
|
|
587
599
|
);
|
|
588
600
|
const tableSteps = dynamodbSharedLib.tableName(
|
|
589
601
|
_izContext,
|
|
590
|
-
|
|
602
|
+
"AwaitingMultipleSteps",
|
|
591
603
|
);
|
|
592
604
|
const tablePending = dynamodbSharedLib.tableName(
|
|
593
605
|
_izContext,
|
|
594
|
-
|
|
606
|
+
"AwaitingMultipleStepByPending",
|
|
595
607
|
);
|
|
596
608
|
|
|
597
609
|
await Promise.all(
|
|
@@ -599,14 +611,14 @@ export async function clearAllAwaitingSteps(_izContext, pendingStepId) {
|
|
|
599
611
|
({ awaitingStepId, pendingStepId: itemPendingStepId }) => [
|
|
600
612
|
dynamodbSharedLib.deleteItem(_izContext, tableSteps, {
|
|
601
613
|
awaitingStepId,
|
|
602
|
-
pendingStepId: itemPendingStepId
|
|
614
|
+
pendingStepId: itemPendingStepId,
|
|
603
615
|
}),
|
|
604
616
|
dynamodbSharedLib.deleteItem(_izContext, tablePending, {
|
|
605
617
|
awaitingStepId,
|
|
606
|
-
pendingStepId: itemPendingStepId
|
|
607
|
-
})
|
|
608
|
-
]
|
|
609
|
-
)
|
|
618
|
+
pendingStepId: itemPendingStepId,
|
|
619
|
+
}),
|
|
620
|
+
],
|
|
621
|
+
),
|
|
610
622
|
);
|
|
611
623
|
|
|
612
624
|
return true;
|
|
@@ -625,12 +637,12 @@ export async function removeAwaitingMultipleStep(
|
|
|
625
637
|
_izContext,
|
|
626
638
|
awaitingStepId,
|
|
627
639
|
pendingStepId,
|
|
628
|
-
errorsFound = []
|
|
640
|
+
errorsFound = [],
|
|
629
641
|
) {
|
|
630
|
-
_izContext.logger.debug(
|
|
642
|
+
_izContext.logger.debug("[Lib:removeAwaitingMultipleStep] Input parameters", {
|
|
631
643
|
awaitingStepId,
|
|
632
644
|
pendingStepId,
|
|
633
|
-
errorsFound
|
|
645
|
+
errorsFound,
|
|
634
646
|
});
|
|
635
647
|
|
|
636
648
|
if (!awaitingStepId || !pendingStepId) {
|
|
@@ -644,9 +656,9 @@ export async function removeAwaitingMultipleStep(
|
|
|
644
656
|
const promises = [
|
|
645
657
|
dynamodbSharedLib.deleteItem(
|
|
646
658
|
_izContext,
|
|
647
|
-
dynamodbSharedLib.tableName(_izContext,
|
|
648
|
-
keys
|
|
649
|
-
)
|
|
659
|
+
dynamodbSharedLib.tableName(_izContext, "AwaitingMultipleSteps"),
|
|
660
|
+
keys,
|
|
661
|
+
),
|
|
650
662
|
];
|
|
651
663
|
|
|
652
664
|
if (errorsFound.length === 0) {
|
|
@@ -655,10 +667,10 @@ export async function removeAwaitingMultipleStep(
|
|
|
655
667
|
_izContext,
|
|
656
668
|
dynamodbSharedLib.tableName(
|
|
657
669
|
_izContext,
|
|
658
|
-
|
|
670
|
+
"AwaitingMultipleStepByPending",
|
|
659
671
|
),
|
|
660
|
-
keys
|
|
661
|
-
)
|
|
672
|
+
keys,
|
|
673
|
+
),
|
|
662
674
|
);
|
|
663
675
|
}
|
|
664
676
|
|
|
@@ -675,9 +687,10 @@ export async function removeAwaitingMultipleStep(
|
|
|
675
687
|
export async function completeAction(
|
|
676
688
|
_izContext,
|
|
677
689
|
parentFlowId,
|
|
678
|
-
prefix =
|
|
690
|
+
prefix = "",
|
|
679
691
|
returnValue = {},
|
|
680
|
-
errorsFound = []
|
|
692
|
+
errorsFound = [],
|
|
693
|
+
settings = { checkIsAllError: false }
|
|
681
694
|
) {
|
|
682
695
|
_izContext.logger.debug('[Lib:CompleteAction] Input parameters', {
|
|
683
696
|
parentFlowId,
|
|
@@ -685,14 +698,17 @@ export async function completeAction(
|
|
|
685
698
|
});
|
|
686
699
|
|
|
687
700
|
try {
|
|
688
|
-
const {
|
|
701
|
+
const {pendingStepId} = await findPendingStepAwaitingMultipleSteps(
|
|
689
702
|
_izContext,
|
|
690
|
-
createAwaitingStepId(
|
|
703
|
+
createAwaitingStepId(
|
|
704
|
+
parentFlowId,
|
|
705
|
+
prefix
|
|
706
|
+
)
|
|
691
707
|
);
|
|
692
708
|
|
|
693
709
|
if (!pendingStepId) {
|
|
694
710
|
_izContext.logger.warn(
|
|
695
|
-
`No pending step found for awaitingStepId: ${awaitingStepId}
|
|
711
|
+
`No pending step found for awaitingStepId: ${awaitingStepId}`,
|
|
696
712
|
);
|
|
697
713
|
return { returnValue, errorsFound };
|
|
698
714
|
}
|
|
@@ -702,11 +718,17 @@ export async function completeAction(
|
|
|
702
718
|
collectedReturnValueByAwaitingStepId,
|
|
703
719
|
collectedErrors,
|
|
704
720
|
returnValues,
|
|
705
|
-
additionalAttributes
|
|
721
|
+
additionalAttributes,
|
|
706
722
|
} = await checkAllAwaitingStepsFinishedWithReturnParams(
|
|
707
723
|
_izContext,
|
|
708
724
|
pendingStepId,
|
|
709
|
-
createAwaitingStepId(
|
|
725
|
+
createAwaitingStepId(
|
|
726
|
+
parentFlowId,
|
|
727
|
+
prefix
|
|
728
|
+
),
|
|
729
|
+
errorsFound,
|
|
730
|
+
returnValue,
|
|
731
|
+
{ checkIsAllError: settings.checkIsAllError }
|
|
710
732
|
);
|
|
711
733
|
|
|
712
734
|
let status = true;
|
|
@@ -721,22 +743,22 @@ export async function completeAction(
|
|
|
721
743
|
|
|
722
744
|
if (status) {
|
|
723
745
|
await Promise.all(
|
|
724
|
-
(
|
|
746
|
+
(additionalAttributes.listOfRecords ?? []).flatMap(records =>
|
|
725
747
|
Object.values(records).map(async record =>
|
|
726
|
-
dynamodbSharedLib.
|
|
748
|
+
dynamodbSharedLib.updateItem(
|
|
727
749
|
_izContext,
|
|
728
750
|
await dynamodbSharedLib.tableName(
|
|
729
751
|
_izContext,
|
|
730
752
|
record.tableName,
|
|
731
|
-
record.serviceTag
|
|
753
|
+
record.serviceTag,
|
|
732
754
|
),
|
|
733
755
|
{
|
|
734
756
|
...record.objInstanceFull.identifiers,
|
|
735
|
-
...record.objInstanceFull.fields
|
|
736
|
-
}
|
|
737
|
-
)
|
|
738
|
-
)
|
|
739
|
-
)
|
|
757
|
+
...record.objInstanceFull.fields,
|
|
758
|
+
},
|
|
759
|
+
),
|
|
760
|
+
),
|
|
761
|
+
),
|
|
740
762
|
);
|
|
741
763
|
}
|
|
742
764
|
|
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];
|
|
@@ -64,13 +64,13 @@ export async function createAwaitingStep(
|
|
|
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
|
|
|
@@ -116,21 +116,21 @@ export async function findPendingStep(_izContext, awaitingStepId) {
|
|
|
116
116
|
export async function removeAwaitingStep(
|
|
117
117
|
_izContext,
|
|
118
118
|
awaitingStepId,
|
|
119
|
-
pendingStepId
|
|
119
|
+
pendingStepId,
|
|
120
120
|
) {
|
|
121
|
-
_izContext.logger.debug(
|
|
121
|
+
_izContext.logger.debug("[Lib:AsyncFlow:removeAwaitingStep] Input", {
|
|
122
122
|
awaitingStepId,
|
|
123
|
-
pendingStepId
|
|
123
|
+
pendingStepId,
|
|
124
124
|
});
|
|
125
125
|
|
|
126
126
|
if (!awaitingStepId || !pendingStepId) {
|
|
127
|
-
throw new NoRetryError(
|
|
127
|
+
throw new NoRetryError("awaitingStepId, pendingStepId required");
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
await dynamodbSharedLib.deleteItem(
|
|
131
131
|
_izContext,
|
|
132
|
-
dynamodbSharedLib.tableName(_izContext,
|
|
133
|
-
{ awaitingStepId, pendingStepId }
|
|
132
|
+
dynamodbSharedLib.tableName(_izContext, "AwaitingStep"),
|
|
133
|
+
{ awaitingStepId, pendingStepId },
|
|
134
134
|
);
|
|
135
135
|
}
|
|
136
136
|
|
|
@@ -150,16 +150,16 @@ export async function removeAwaitingStepWithCheckUniqueRequestId(
|
|
|
150
150
|
awaitingStepId,
|
|
151
151
|
pendingStepId,
|
|
152
152
|
checkUniqueRequestId,
|
|
153
|
-
prefix =
|
|
153
|
+
prefix = "",
|
|
154
154
|
) {
|
|
155
155
|
_izContext.logger.debug(
|
|
156
|
-
|
|
157
|
-
{ awaitingStepId, pendingStepId, checkUniqueRequestId, prefix }
|
|
156
|
+
"[Lib:AsyncFlow:removeAwaitingStepWithCheckUniqueRequestId] Input",
|
|
157
|
+
{ awaitingStepId, pendingStepId, checkUniqueRequestId, prefix },
|
|
158
158
|
);
|
|
159
159
|
|
|
160
160
|
if (!awaitingStepId || !pendingStepId || !checkUniqueRequestId) {
|
|
161
161
|
throw new NoRetryError(
|
|
162
|
-
|
|
162
|
+
"awaitingStepId, pendingStepId, checkUniqueRequestId required",
|
|
163
163
|
);
|
|
164
164
|
}
|
|
165
165
|
|
|
@@ -167,19 +167,19 @@ export async function removeAwaitingStepWithCheckUniqueRequestId(
|
|
|
167
167
|
additionalAttributes: { checkUniqueRequestId },
|
|
168
168
|
logicalElements: [
|
|
169
169
|
{
|
|
170
|
-
type:
|
|
171
|
-
comparison:
|
|
170
|
+
type: "logical",
|
|
171
|
+
comparison: "equals",
|
|
172
172
|
lhsAttribute: createFieldNameUniqueRequestId(prefix),
|
|
173
|
-
rhsReference:
|
|
174
|
-
}
|
|
175
|
-
]
|
|
173
|
+
rhsReference: "checkUniqueRequestId",
|
|
174
|
+
},
|
|
175
|
+
],
|
|
176
176
|
};
|
|
177
177
|
|
|
178
178
|
await dynamodbSharedLib.deleteItem(
|
|
179
179
|
_izContext,
|
|
180
|
-
dynamodbSharedLib.tableName(_izContext,
|
|
180
|
+
dynamodbSharedLib.tableName(_izContext, "AwaitingStep"),
|
|
181
181
|
{ awaitingStepId, pendingStepId },
|
|
182
182
|
queryElementsCondition,
|
|
183
|
-
{ errorOnConditionalExpNotPass: false }
|
|
183
|
+
{ errorOnConditionalExpNotPass: false },
|
|
184
184
|
);
|
|
185
185
|
}
|