@izara_project/izara-core-library-asynchronous-flow 1.0.49 → 1.0.51
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 +126 -99
- 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.51",
|
|
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,14 @@ 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
|
-
|
|
159
|
-
finalRecords = records.map(record => {
|
|
158
|
+
if (hasFlowPublish) {
|
|
159
|
+
finalRecords = records.map((record) => {
|
|
160
|
+
|
|
160
161
|
const recordFlowType = record.flowType || flowType;
|
|
161
162
|
|
|
162
163
|
if (
|
|
@@ -165,26 +166,28 @@ export async function createAwaitingMultipleSteps(
|
|
|
165
166
|
!recordFlowType.serviceTag
|
|
166
167
|
) {
|
|
167
168
|
throw new NoRetryError(
|
|
168
|
-
|
|
169
|
+
"record.flowType must have both flowTag and serviceTag",
|
|
169
170
|
);
|
|
170
171
|
}
|
|
171
172
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
173
|
+
let awaitingStepId = record.awaitingStepId;
|
|
174
|
+
|
|
175
|
+
if (!awaitingStepId) {
|
|
176
|
+
awaitingStepId = createParentFlowId();
|
|
177
|
+
}
|
|
175
178
|
|
|
176
179
|
return {
|
|
177
180
|
awaitingStepId,
|
|
178
181
|
additionalAttributes: record.additionalAttributes,
|
|
179
182
|
message: {
|
|
180
183
|
...record.message,
|
|
181
|
-
parentFlowId: awaitingStepId
|
|
184
|
+
parentFlowId: awaitingStepId,
|
|
182
185
|
},
|
|
183
186
|
topicArn: snsSharedLib.snsTopicArnByFlowSchema(
|
|
184
187
|
_izContext,
|
|
185
188
|
recordFlowType.flowTag,
|
|
186
|
-
recordFlowType.serviceTag
|
|
187
|
-
)
|
|
189
|
+
recordFlowType.serviceTag,
|
|
190
|
+
),
|
|
188
191
|
};
|
|
189
192
|
});
|
|
190
193
|
}
|
|
@@ -204,7 +207,7 @@ export async function createAwaitingMultipleSteps(
|
|
|
204
207
|
awaitingStepId: createAwaitingStepId(awaitingStepId, prefix),
|
|
205
208
|
additionalAttributes: mergedAttributes
|
|
206
209
|
};
|
|
207
|
-
}
|
|
210
|
+
},
|
|
208
211
|
);
|
|
209
212
|
|
|
210
213
|
await _putAwaitingMultipleStepRecords(
|
|
@@ -213,8 +216,8 @@ export async function createAwaitingMultipleSteps(
|
|
|
213
216
|
finalPendingStepId,
|
|
214
217
|
{
|
|
215
218
|
complete: false,
|
|
216
|
-
errorsFound: []
|
|
217
|
-
}
|
|
219
|
+
errorsFound: [],
|
|
220
|
+
},
|
|
218
221
|
);
|
|
219
222
|
|
|
220
223
|
if (hasFlowPublish) {
|
|
@@ -222,9 +225,9 @@ export async function createAwaitingMultipleSteps(
|
|
|
222
225
|
finalRecords.map(async ({ message, topicArn }) => {
|
|
223
226
|
await sns.publishAsync(_izContext, {
|
|
224
227
|
TopicArn: `${topicArn}_In`,
|
|
225
|
-
Message: JSON.stringify(message)
|
|
228
|
+
Message: JSON.stringify(message),
|
|
226
229
|
});
|
|
227
|
-
})
|
|
230
|
+
}),
|
|
228
231
|
);
|
|
229
232
|
}
|
|
230
233
|
|
|
@@ -247,23 +250,23 @@ export async function updateAwaitingMultipleStep(
|
|
|
247
250
|
_izContext,
|
|
248
251
|
awaitingStepId,
|
|
249
252
|
pendingStepId,
|
|
250
|
-
data
|
|
253
|
+
data,
|
|
251
254
|
) {
|
|
252
255
|
const tableSteps = dynamodbSharedLib.tableName(
|
|
253
256
|
_izContext,
|
|
254
|
-
|
|
257
|
+
"AwaitingMultipleSteps",
|
|
255
258
|
);
|
|
256
259
|
|
|
257
260
|
await dynamodbSharedLib.updateItem(
|
|
258
261
|
_izContext,
|
|
259
262
|
tableSteps,
|
|
260
263
|
{ awaitingStepId, pendingStepId },
|
|
261
|
-
data
|
|
264
|
+
data,
|
|
262
265
|
);
|
|
263
266
|
|
|
264
|
-
_izContext.logger.debug(
|
|
267
|
+
_izContext.logger.debug("[Lib:updateAwaitingMultipleStep] Output", {
|
|
265
268
|
awaitingStepId,
|
|
266
|
-
data
|
|
269
|
+
data,
|
|
267
270
|
});
|
|
268
271
|
|
|
269
272
|
return { ...data, awaitingStepId };
|
|
@@ -278,15 +281,15 @@ export async function updateAwaitingMultipleStep(
|
|
|
278
281
|
*/
|
|
279
282
|
export async function findPendingStepAwaitingMultipleSteps(
|
|
280
283
|
_izContext,
|
|
281
|
-
awaitingStepId
|
|
284
|
+
awaitingStepId,
|
|
282
285
|
) {
|
|
283
|
-
_izContext.logger.debug(
|
|
284
|
-
awaitingStepId
|
|
286
|
+
_izContext.logger.debug("[Lib:findPendingStepAwaitingMultipleSteps] Input", {
|
|
287
|
+
awaitingStepId,
|
|
285
288
|
});
|
|
286
289
|
|
|
287
290
|
const items = await _queryPendingStepsByAwaitingStepId(
|
|
288
291
|
_izContext,
|
|
289
|
-
awaitingStepId
|
|
292
|
+
awaitingStepId,
|
|
290
293
|
);
|
|
291
294
|
|
|
292
295
|
if (items && items.length > 0) {
|
|
@@ -304,7 +307,7 @@ export async function findPendingStepAwaitingMultipleSteps(
|
|
|
304
307
|
*/
|
|
305
308
|
export async function findPendingStepsAwaitingMultipleSteps(
|
|
306
309
|
_izContext,
|
|
307
|
-
awaitingStepId
|
|
310
|
+
awaitingStepId,
|
|
308
311
|
) {
|
|
309
312
|
return _queryPendingStepsByAwaitingStepId(_izContext, awaitingStepId);
|
|
310
313
|
}
|
|
@@ -318,11 +321,11 @@ export async function findPendingStepsAwaitingMultipleSteps(
|
|
|
318
321
|
*/
|
|
319
322
|
export async function findPendingStepIdAwaitingMultipleSteps(
|
|
320
323
|
_izContext,
|
|
321
|
-
awaitingStepId
|
|
324
|
+
awaitingStepId,
|
|
322
325
|
) {
|
|
323
326
|
const items = await _queryPendingStepsByAwaitingStepId(
|
|
324
327
|
_izContext,
|
|
325
|
-
awaitingStepId
|
|
328
|
+
awaitingStepId,
|
|
326
329
|
);
|
|
327
330
|
if (items && items[0] && items[0].pendingStepId) {
|
|
328
331
|
return items[0].pendingStepId;
|
|
@@ -339,7 +342,7 @@ export async function findPendingStepIdAwaitingMultipleSteps(
|
|
|
339
342
|
*/
|
|
340
343
|
export async function findAwaitingMultipleStepByPending(
|
|
341
344
|
_izContext,
|
|
342
|
-
pendingStepId
|
|
345
|
+
pendingStepId,
|
|
343
346
|
) {
|
|
344
347
|
return _queryAwaitingStepsByPendingStepId(_izContext, pendingStepId);
|
|
345
348
|
}
|
|
@@ -362,16 +365,16 @@ export async function checkAllAwaitingStepsFinishedWithReturnParams(
|
|
|
362
365
|
currentAwaitingStepId,
|
|
363
366
|
errorsFound = [],
|
|
364
367
|
returnValues = {},
|
|
365
|
-
settings = { checkIsAllError: false }
|
|
368
|
+
settings = { checkIsAllError: false },
|
|
366
369
|
) {
|
|
367
370
|
_izContext.logger.debug(
|
|
368
|
-
|
|
371
|
+
"[Lib:checkAllAwaitingStepsFinishedWithReturnParams] Input parameters",
|
|
369
372
|
{
|
|
370
373
|
pendingStepId,
|
|
371
374
|
currentAwaitingStepId,
|
|
372
375
|
errorsFound,
|
|
373
|
-
returnValues
|
|
374
|
-
}
|
|
376
|
+
returnValues,
|
|
377
|
+
},
|
|
375
378
|
);
|
|
376
379
|
|
|
377
380
|
_assertPendingStepId(pendingStepId);
|
|
@@ -390,16 +393,26 @@ export async function checkAllAwaitingStepsFinishedWithReturnParams(
|
|
|
390
393
|
|
|
391
394
|
await dynamodbSharedLib.updateItem(
|
|
392
395
|
_izContext,
|
|
393
|
-
dynamodbSharedLib.tableName(_izContext,
|
|
396
|
+
dynamodbSharedLib.tableName(_izContext, "AwaitingMultipleStepByPending"),
|
|
394
397
|
{
|
|
395
398
|
pendingStepId,
|
|
396
|
-
awaitingStepId: currentAwaitingStepId
|
|
399
|
+
awaitingStepId: currentAwaitingStepId,
|
|
397
400
|
},
|
|
398
401
|
{
|
|
399
402
|
complete: true,
|
|
400
403
|
errorsFound,
|
|
401
|
-
returnValues
|
|
402
|
-
}
|
|
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
|
+
},
|
|
403
416
|
);
|
|
404
417
|
|
|
405
418
|
_izContext.logger.debug(
|
|
@@ -415,10 +428,12 @@ export async function checkAllAwaitingStepsFinishedWithReturnParams(
|
|
|
415
428
|
|
|
416
429
|
const awaitingStepItems = await _queryAwaitingStepsByPendingStepId(
|
|
417
430
|
_izContext,
|
|
418
|
-
pendingStepId
|
|
431
|
+
pendingStepId,
|
|
419
432
|
);
|
|
420
433
|
|
|
421
434
|
_izContext.logger.debug(
|
|
435
|
+
"[Lib:checkAllAwaitingStepsFinishedWithReturnParams] awaitingStepItems",
|
|
436
|
+
{ awaitingStepItems },
|
|
422
437
|
'[Lib:checkAllAwaitingStepsFinishedWithReturnParams] Queried awaitingStepItems',
|
|
423
438
|
{
|
|
424
439
|
pendingStepId,
|
|
@@ -444,7 +459,7 @@ export async function checkAllAwaitingStepsFinishedWithReturnParams(
|
|
|
444
459
|
}
|
|
445
460
|
|
|
446
461
|
const hasIncomplete = awaitingStepItems.some(
|
|
447
|
-
item => item.awaitingStepId !== currentAwaitingStepId && !item.complete
|
|
462
|
+
(item) => item.awaitingStepId !== currentAwaitingStepId && !item.complete,
|
|
448
463
|
);
|
|
449
464
|
|
|
450
465
|
let defaultAttrs = null;
|
|
@@ -515,7 +530,7 @@ export async function checkAllAwaitingStepsFinishedWithReturnParams(
|
|
|
515
530
|
collectedReturnValueByAwaitingStepId: null,
|
|
516
531
|
collectedErrors: [],
|
|
517
532
|
returnValues: null,
|
|
518
|
-
additionalAttributes: defaultAttrs
|
|
533
|
+
additionalAttributes: defaultAttrs,
|
|
519
534
|
};
|
|
520
535
|
}
|
|
521
536
|
|
|
@@ -539,7 +554,7 @@ export async function checkAllAwaitingStepsFinishedWithReturnParams(
|
|
|
539
554
|
if (item.errorsFound && item.errorsFound.length > 0) {
|
|
540
555
|
collectedErrors.push(
|
|
541
556
|
`Error found in step ${item.awaitingStepId}`,
|
|
542
|
-
...item.errorsFound
|
|
557
|
+
...item.errorsFound,
|
|
543
558
|
);
|
|
544
559
|
}
|
|
545
560
|
}
|
|
@@ -549,12 +564,12 @@ export async function checkAllAwaitingStepsFinishedWithReturnParams(
|
|
|
549
564
|
collectedReturnValueByAwaitingStepId,
|
|
550
565
|
collectedErrors,
|
|
551
566
|
returnValues: sharedReturnValues,
|
|
552
|
-
additionalAttributes: defaultAttrs
|
|
567
|
+
additionalAttributes: defaultAttrs,
|
|
553
568
|
};
|
|
554
569
|
|
|
555
570
|
if (settings.checkIsAllError) {
|
|
556
571
|
result.isAllError = awaitingStepItems.every(
|
|
557
|
-
item => item.errorsFound && item.errorsFound.length > 0
|
|
572
|
+
(item) => item.errorsFound && item.errorsFound.length > 0,
|
|
558
573
|
);
|
|
559
574
|
}
|
|
560
575
|
|
|
@@ -577,21 +592,21 @@ export async function checkAllAwaitingStepsFinishedWithReturnParams(
|
|
|
577
592
|
* @returns {Promise<boolean>} True if operations completed successfully.
|
|
578
593
|
*/
|
|
579
594
|
export async function clearAllAwaitingSteps(_izContext, pendingStepId) {
|
|
580
|
-
_izContext.logger.debug(
|
|
581
|
-
pendingStepId
|
|
595
|
+
_izContext.logger.debug("[Lib:clearAllAwaitingSteps] Input parameters", {
|
|
596
|
+
pendingStepId,
|
|
582
597
|
});
|
|
583
598
|
|
|
584
599
|
const awaitingStepItems = await _queryAwaitingStepsByPendingStepId(
|
|
585
600
|
_izContext,
|
|
586
|
-
pendingStepId
|
|
601
|
+
pendingStepId,
|
|
587
602
|
);
|
|
588
603
|
const tableSteps = dynamodbSharedLib.tableName(
|
|
589
604
|
_izContext,
|
|
590
|
-
|
|
605
|
+
"AwaitingMultipleSteps",
|
|
591
606
|
);
|
|
592
607
|
const tablePending = dynamodbSharedLib.tableName(
|
|
593
608
|
_izContext,
|
|
594
|
-
|
|
609
|
+
"AwaitingMultipleStepByPending",
|
|
595
610
|
);
|
|
596
611
|
|
|
597
612
|
await Promise.all(
|
|
@@ -599,14 +614,14 @@ export async function clearAllAwaitingSteps(_izContext, pendingStepId) {
|
|
|
599
614
|
({ awaitingStepId, pendingStepId: itemPendingStepId }) => [
|
|
600
615
|
dynamodbSharedLib.deleteItem(_izContext, tableSteps, {
|
|
601
616
|
awaitingStepId,
|
|
602
|
-
pendingStepId: itemPendingStepId
|
|
617
|
+
pendingStepId: itemPendingStepId,
|
|
603
618
|
}),
|
|
604
619
|
dynamodbSharedLib.deleteItem(_izContext, tablePending, {
|
|
605
620
|
awaitingStepId,
|
|
606
|
-
pendingStepId: itemPendingStepId
|
|
607
|
-
})
|
|
608
|
-
]
|
|
609
|
-
)
|
|
621
|
+
pendingStepId: itemPendingStepId,
|
|
622
|
+
}),
|
|
623
|
+
],
|
|
624
|
+
),
|
|
610
625
|
);
|
|
611
626
|
|
|
612
627
|
return true;
|
|
@@ -625,12 +640,12 @@ export async function removeAwaitingMultipleStep(
|
|
|
625
640
|
_izContext,
|
|
626
641
|
awaitingStepId,
|
|
627
642
|
pendingStepId,
|
|
628
|
-
errorsFound = []
|
|
643
|
+
errorsFound = [],
|
|
629
644
|
) {
|
|
630
|
-
_izContext.logger.debug(
|
|
645
|
+
_izContext.logger.debug("[Lib:removeAwaitingMultipleStep] Input parameters", {
|
|
631
646
|
awaitingStepId,
|
|
632
647
|
pendingStepId,
|
|
633
|
-
errorsFound
|
|
648
|
+
errorsFound,
|
|
634
649
|
});
|
|
635
650
|
|
|
636
651
|
if (!awaitingStepId || !pendingStepId) {
|
|
@@ -644,9 +659,9 @@ export async function removeAwaitingMultipleStep(
|
|
|
644
659
|
const promises = [
|
|
645
660
|
dynamodbSharedLib.deleteItem(
|
|
646
661
|
_izContext,
|
|
647
|
-
dynamodbSharedLib.tableName(_izContext,
|
|
648
|
-
keys
|
|
649
|
-
)
|
|
662
|
+
dynamodbSharedLib.tableName(_izContext, "AwaitingMultipleSteps"),
|
|
663
|
+
keys,
|
|
664
|
+
),
|
|
650
665
|
];
|
|
651
666
|
|
|
652
667
|
if (errorsFound.length === 0) {
|
|
@@ -655,10 +670,10 @@ export async function removeAwaitingMultipleStep(
|
|
|
655
670
|
_izContext,
|
|
656
671
|
dynamodbSharedLib.tableName(
|
|
657
672
|
_izContext,
|
|
658
|
-
|
|
673
|
+
"AwaitingMultipleStepByPending",
|
|
659
674
|
),
|
|
660
|
-
keys
|
|
661
|
-
)
|
|
675
|
+
keys,
|
|
676
|
+
),
|
|
662
677
|
);
|
|
663
678
|
}
|
|
664
679
|
|
|
@@ -675,9 +690,10 @@ export async function removeAwaitingMultipleStep(
|
|
|
675
690
|
export async function completeAction(
|
|
676
691
|
_izContext,
|
|
677
692
|
parentFlowId,
|
|
678
|
-
prefix =
|
|
693
|
+
prefix = "",
|
|
679
694
|
returnValue = {},
|
|
680
|
-
errorsFound = []
|
|
695
|
+
errorsFound = [],
|
|
696
|
+
settings = { checkIsAllError: false }
|
|
681
697
|
) {
|
|
682
698
|
_izContext.logger.debug('[Lib:CompleteAction] Input parameters', {
|
|
683
699
|
parentFlowId,
|
|
@@ -685,14 +701,17 @@ export async function completeAction(
|
|
|
685
701
|
});
|
|
686
702
|
|
|
687
703
|
try {
|
|
688
|
-
const {
|
|
704
|
+
const {pendingStepId} = await findPendingStepAwaitingMultipleSteps(
|
|
689
705
|
_izContext,
|
|
690
|
-
createAwaitingStepId(
|
|
706
|
+
createAwaitingStepId(
|
|
707
|
+
parentFlowId,
|
|
708
|
+
prefix
|
|
709
|
+
)
|
|
691
710
|
);
|
|
692
711
|
|
|
693
712
|
if (!pendingStepId) {
|
|
694
713
|
_izContext.logger.warn(
|
|
695
|
-
`No pending step found for awaitingStepId: ${awaitingStepId}
|
|
714
|
+
`No pending step found for awaitingStepId: ${awaitingStepId}`,
|
|
696
715
|
);
|
|
697
716
|
return { returnValue, errorsFound };
|
|
698
717
|
}
|
|
@@ -702,11 +721,17 @@ export async function completeAction(
|
|
|
702
721
|
collectedReturnValueByAwaitingStepId,
|
|
703
722
|
collectedErrors,
|
|
704
723
|
returnValues,
|
|
705
|
-
additionalAttributes
|
|
724
|
+
additionalAttributes,
|
|
706
725
|
} = await checkAllAwaitingStepsFinishedWithReturnParams(
|
|
707
726
|
_izContext,
|
|
708
727
|
pendingStepId,
|
|
709
|
-
createAwaitingStepId(
|
|
728
|
+
createAwaitingStepId(
|
|
729
|
+
parentFlowId,
|
|
730
|
+
prefix
|
|
731
|
+
),
|
|
732
|
+
errorsFound,
|
|
733
|
+
returnValue,
|
|
734
|
+
{ checkIsAllError: settings.checkIsAllError }
|
|
710
735
|
);
|
|
711
736
|
|
|
712
737
|
let status = true;
|
|
@@ -721,22 +746,24 @@ export async function completeAction(
|
|
|
721
746
|
|
|
722
747
|
if (status) {
|
|
723
748
|
await Promise.all(
|
|
724
|
-
(
|
|
749
|
+
(additionalAttributes.listOfRecords ?? []).flatMap(records =>
|
|
725
750
|
Object.values(records).map(async record =>
|
|
726
|
-
dynamodbSharedLib.
|
|
751
|
+
dynamodbSharedLib.updateItem(
|
|
727
752
|
_izContext,
|
|
728
753
|
await dynamodbSharedLib.tableName(
|
|
729
754
|
_izContext,
|
|
730
755
|
record.tableName,
|
|
731
|
-
record.serviceTag
|
|
756
|
+
record.serviceTag,
|
|
732
757
|
),
|
|
733
758
|
{
|
|
734
759
|
...record.objInstanceFull.identifiers,
|
|
735
|
-
|
|
760
|
+
},
|
|
761
|
+
{
|
|
762
|
+
...record.objInstanceFull.fields,
|
|
736
763
|
}
|
|
737
|
-
)
|
|
738
|
-
)
|
|
739
|
-
)
|
|
764
|
+
),
|
|
765
|
+
),
|
|
766
|
+
),
|
|
740
767
|
);
|
|
741
768
|
}
|
|
742
769
|
|
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
|
}
|