@izara_project/izara-core-library-asynchronous-flow 1.0.50 → 1.0.52
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 +125 -117
- 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.52",
|
|
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,22 +127,22 @@ 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
|
|
|
@@ -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(
|
|
159
|
+
finalRecords = records.map(record => {
|
|
160
160
|
const recordFlowType = record.flowType || flowType;
|
|
161
161
|
|
|
162
162
|
if (
|
|
@@ -165,26 +165,28 @@ 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
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
172
|
+
let awaitingStepId = record.awaitingStepId;
|
|
173
|
+
|
|
174
|
+
if (!awaitingStepId) {
|
|
175
|
+
awaitingStepId = createParentFlowId();
|
|
176
|
+
}
|
|
175
177
|
|
|
176
178
|
return {
|
|
177
179
|
awaitingStepId,
|
|
178
180
|
additionalAttributes: record.additionalAttributes,
|
|
179
181
|
message: {
|
|
180
182
|
...record.message,
|
|
181
|
-
parentFlowId: awaitingStepId
|
|
183
|
+
parentFlowId: awaitingStepId
|
|
182
184
|
},
|
|
183
185
|
topicArn: snsSharedLib.snsTopicArnByFlowSchema(
|
|
184
186
|
_izContext,
|
|
185
187
|
recordFlowType.flowTag,
|
|
186
|
-
recordFlowType.serviceTag
|
|
187
|
-
)
|
|
188
|
+
recordFlowType.serviceTag
|
|
189
|
+
)
|
|
188
190
|
};
|
|
189
191
|
});
|
|
190
192
|
}
|
|
@@ -204,7 +206,7 @@ export async function createAwaitingMultipleSteps(
|
|
|
204
206
|
awaitingStepId: createAwaitingStepId(awaitingStepId, prefix),
|
|
205
207
|
additionalAttributes: mergedAttributes
|
|
206
208
|
};
|
|
207
|
-
}
|
|
209
|
+
}
|
|
208
210
|
);
|
|
209
211
|
|
|
210
212
|
await _putAwaitingMultipleStepRecords(
|
|
@@ -213,8 +215,8 @@ export async function createAwaitingMultipleSteps(
|
|
|
213
215
|
finalPendingStepId,
|
|
214
216
|
{
|
|
215
217
|
complete: false,
|
|
216
|
-
errorsFound: []
|
|
217
|
-
}
|
|
218
|
+
errorsFound: []
|
|
219
|
+
}
|
|
218
220
|
);
|
|
219
221
|
|
|
220
222
|
if (hasFlowPublish) {
|
|
@@ -222,9 +224,9 @@ export async function createAwaitingMultipleSteps(
|
|
|
222
224
|
finalRecords.map(async ({ message, topicArn }) => {
|
|
223
225
|
await sns.publishAsync(_izContext, {
|
|
224
226
|
TopicArn: `${topicArn}_In`,
|
|
225
|
-
Message: JSON.stringify(message)
|
|
227
|
+
Message: JSON.stringify(message)
|
|
226
228
|
});
|
|
227
|
-
})
|
|
229
|
+
})
|
|
228
230
|
);
|
|
229
231
|
}
|
|
230
232
|
|
|
@@ -243,27 +245,27 @@ export async function createAwaitingMultipleSteps(
|
|
|
243
245
|
* @param {object} data - Attributes to update.
|
|
244
246
|
* @returns {Promise<object>} The updated data with awaitingStepId merged.
|
|
245
247
|
*/
|
|
246
|
-
|
|
248
|
+
async function updateAwaitingMultipleStep(
|
|
247
249
|
_izContext,
|
|
248
250
|
awaitingStepId,
|
|
249
251
|
pendingStepId,
|
|
250
|
-
data
|
|
252
|
+
data
|
|
251
253
|
) {
|
|
252
254
|
const tableSteps = dynamodbSharedLib.tableName(
|
|
253
255
|
_izContext,
|
|
254
|
-
|
|
256
|
+
'AwaitingMultipleSteps'
|
|
255
257
|
);
|
|
256
258
|
|
|
257
259
|
await dynamodbSharedLib.updateItem(
|
|
258
260
|
_izContext,
|
|
259
261
|
tableSteps,
|
|
260
262
|
{ awaitingStepId, pendingStepId },
|
|
261
|
-
data
|
|
263
|
+
data
|
|
262
264
|
);
|
|
263
265
|
|
|
264
|
-
_izContext.logger.debug(
|
|
266
|
+
_izContext.logger.debug('[Lib:updateAwaitingMultipleStep] Output', {
|
|
265
267
|
awaitingStepId,
|
|
266
|
-
data
|
|
268
|
+
data
|
|
267
269
|
});
|
|
268
270
|
|
|
269
271
|
return { ...data, awaitingStepId };
|
|
@@ -276,17 +278,17 @@ export async function updateAwaitingMultipleStep(
|
|
|
276
278
|
* @param {string} awaitingStepId - The ID of the awaiting step.
|
|
277
279
|
* @returns {Promise<object|null>} The found item or null.
|
|
278
280
|
*/
|
|
279
|
-
|
|
281
|
+
async function findPendingStepAwaitingMultipleSteps(
|
|
280
282
|
_izContext,
|
|
281
|
-
awaitingStepId
|
|
283
|
+
awaitingStepId
|
|
282
284
|
) {
|
|
283
|
-
_izContext.logger.debug(
|
|
284
|
-
awaitingStepId
|
|
285
|
+
_izContext.logger.debug('[Lib:findPendingStepAwaitingMultipleSteps] Input', {
|
|
286
|
+
awaitingStepId
|
|
285
287
|
});
|
|
286
288
|
|
|
287
289
|
const items = await _queryPendingStepsByAwaitingStepId(
|
|
288
290
|
_izContext,
|
|
289
|
-
awaitingStepId
|
|
291
|
+
awaitingStepId
|
|
290
292
|
);
|
|
291
293
|
|
|
292
294
|
if (items && items.length > 0) {
|
|
@@ -302,9 +304,9 @@ export async function findPendingStepAwaitingMultipleSteps(
|
|
|
302
304
|
* @param {string} awaitingStepId - The ID of the awaiting step.
|
|
303
305
|
* @returns {Promise<Array<object>>} List of matching items.
|
|
304
306
|
*/
|
|
305
|
-
|
|
307
|
+
async function findPendingStepsAwaitingMultipleSteps(
|
|
306
308
|
_izContext,
|
|
307
|
-
awaitingStepId
|
|
309
|
+
awaitingStepId
|
|
308
310
|
) {
|
|
309
311
|
return _queryPendingStepsByAwaitingStepId(_izContext, awaitingStepId);
|
|
310
312
|
}
|
|
@@ -316,13 +318,13 @@ export async function findPendingStepsAwaitingMultipleSteps(
|
|
|
316
318
|
* @param {string} awaitingStepId - The ID of the awaiting step.
|
|
317
319
|
* @returns {Promise<string|null>} pendingStepId of first item found or null.
|
|
318
320
|
*/
|
|
319
|
-
|
|
321
|
+
async function findPendingStepIdAwaitingMultipleSteps(
|
|
320
322
|
_izContext,
|
|
321
|
-
awaitingStepId
|
|
323
|
+
awaitingStepId
|
|
322
324
|
) {
|
|
323
325
|
const items = await _queryPendingStepsByAwaitingStepId(
|
|
324
326
|
_izContext,
|
|
325
|
-
awaitingStepId
|
|
327
|
+
awaitingStepId
|
|
326
328
|
);
|
|
327
329
|
if (items && items[0] && items[0].pendingStepId) {
|
|
328
330
|
return items[0].pendingStepId;
|
|
@@ -337,10 +339,7 @@ export async function findPendingStepIdAwaitingMultipleSteps(
|
|
|
337
339
|
* @param {string} pendingStepId - The ID of the pending step.
|
|
338
340
|
* @returns {Promise<Array<object>>} List of matching items.
|
|
339
341
|
*/
|
|
340
|
-
|
|
341
|
-
_izContext,
|
|
342
|
-
pendingStepId,
|
|
343
|
-
) {
|
|
342
|
+
async function findAwaitingMultipleStepByPending(_izContext, pendingStepId) {
|
|
344
343
|
return _queryAwaitingStepsByPendingStepId(_izContext, pendingStepId);
|
|
345
344
|
}
|
|
346
345
|
|
|
@@ -356,22 +355,22 @@ export async function findAwaitingMultipleStepByPending(
|
|
|
356
355
|
* @param {boolean} [settings.checkIsAllError=false] - Verify all failed.
|
|
357
356
|
* @returns {Promise<object>} Status object containing completion details.
|
|
358
357
|
*/
|
|
359
|
-
|
|
358
|
+
async function checkAllAwaitingStepsFinishedWithReturnParams(
|
|
360
359
|
_izContext,
|
|
361
360
|
pendingStepId,
|
|
362
361
|
currentAwaitingStepId,
|
|
363
362
|
errorsFound = [],
|
|
364
363
|
returnValues = {},
|
|
365
|
-
settings = { checkIsAllError: false }
|
|
364
|
+
settings = { checkIsAllError: false }
|
|
366
365
|
) {
|
|
367
366
|
_izContext.logger.debug(
|
|
368
|
-
|
|
367
|
+
'[Lib:checkAllAwaitingStepsFinishedWithReturnParams] Input parameters',
|
|
369
368
|
{
|
|
370
369
|
pendingStepId,
|
|
371
370
|
currentAwaitingStepId,
|
|
372
371
|
errorsFound,
|
|
373
|
-
returnValues
|
|
374
|
-
}
|
|
372
|
+
returnValues
|
|
373
|
+
}
|
|
375
374
|
);
|
|
376
375
|
|
|
377
376
|
_assertPendingStepId(pendingStepId);
|
|
@@ -390,16 +389,16 @@ export async function checkAllAwaitingStepsFinishedWithReturnParams(
|
|
|
390
389
|
|
|
391
390
|
await dynamodbSharedLib.updateItem(
|
|
392
391
|
_izContext,
|
|
393
|
-
dynamodbSharedLib.tableName(_izContext,
|
|
392
|
+
dynamodbSharedLib.tableName(_izContext, 'AwaitingMultipleStepByPending'),
|
|
394
393
|
{
|
|
395
394
|
pendingStepId,
|
|
396
|
-
awaitingStepId: currentAwaitingStepId
|
|
395
|
+
awaitingStepId: currentAwaitingStepId
|
|
397
396
|
},
|
|
398
397
|
{
|
|
399
398
|
complete: true,
|
|
400
399
|
errorsFound,
|
|
401
|
-
returnValues
|
|
402
|
-
}
|
|
400
|
+
returnValues
|
|
401
|
+
}
|
|
403
402
|
);
|
|
404
403
|
|
|
405
404
|
_izContext.logger.debug(
|
|
@@ -408,8 +407,8 @@ export async function checkAllAwaitingStepsFinishedWithReturnParams(
|
|
|
408
407
|
pendingStepId,
|
|
409
408
|
awaitingStepId: currentAwaitingStepId,
|
|
410
409
|
errorsFound,
|
|
411
|
-
returnValues
|
|
412
|
-
}
|
|
410
|
+
returnValues
|
|
411
|
+
}
|
|
413
412
|
);
|
|
414
413
|
|
|
415
414
|
_izContext.logger.debug(
|
|
@@ -425,11 +424,11 @@ export async function checkAllAwaitingStepsFinishedWithReturnParams(
|
|
|
425
424
|
|
|
426
425
|
const awaitingStepItems = await _queryAwaitingStepsByPendingStepId(
|
|
427
426
|
_izContext,
|
|
428
|
-
pendingStepId
|
|
427
|
+
pendingStepId
|
|
429
428
|
);
|
|
430
429
|
|
|
431
430
|
_izContext.logger.debug(
|
|
432
|
-
|
|
431
|
+
'[Lib:checkAllAwaitingStepsFinishedWithReturnParams] awaitingStepItems',
|
|
433
432
|
{ awaitingStepItems },
|
|
434
433
|
'[Lib:checkAllAwaitingStepsFinishedWithReturnParams] Queried awaitingStepItems',
|
|
435
434
|
{
|
|
@@ -456,7 +455,7 @@ export async function checkAllAwaitingStepsFinishedWithReturnParams(
|
|
|
456
455
|
}
|
|
457
456
|
|
|
458
457
|
const hasIncomplete = awaitingStepItems.some(
|
|
459
|
-
|
|
458
|
+
item => item.awaitingStepId !== currentAwaitingStepId && !item.complete
|
|
460
459
|
);
|
|
461
460
|
|
|
462
461
|
let defaultAttrs = null;
|
|
@@ -527,7 +526,7 @@ export async function checkAllAwaitingStepsFinishedWithReturnParams(
|
|
|
527
526
|
collectedReturnValueByAwaitingStepId: null,
|
|
528
527
|
collectedErrors: [],
|
|
529
528
|
returnValues: null,
|
|
530
|
-
additionalAttributes: defaultAttrs
|
|
529
|
+
additionalAttributes: defaultAttrs
|
|
531
530
|
};
|
|
532
531
|
}
|
|
533
532
|
|
|
@@ -551,7 +550,7 @@ export async function checkAllAwaitingStepsFinishedWithReturnParams(
|
|
|
551
550
|
if (item.errorsFound && item.errorsFound.length > 0) {
|
|
552
551
|
collectedErrors.push(
|
|
553
552
|
`Error found in step ${item.awaitingStepId}`,
|
|
554
|
-
...item.errorsFound
|
|
553
|
+
...item.errorsFound
|
|
555
554
|
);
|
|
556
555
|
}
|
|
557
556
|
}
|
|
@@ -561,12 +560,12 @@ export async function checkAllAwaitingStepsFinishedWithReturnParams(
|
|
|
561
560
|
collectedReturnValueByAwaitingStepId,
|
|
562
561
|
collectedErrors,
|
|
563
562
|
returnValues: sharedReturnValues,
|
|
564
|
-
additionalAttributes: defaultAttrs
|
|
563
|
+
additionalAttributes: defaultAttrs
|
|
565
564
|
};
|
|
566
565
|
|
|
567
566
|
if (settings.checkIsAllError) {
|
|
568
567
|
result.isAllError = awaitingStepItems.every(
|
|
569
|
-
|
|
568
|
+
item => item.errorsFound && item.errorsFound.length > 0
|
|
570
569
|
);
|
|
571
570
|
}
|
|
572
571
|
|
|
@@ -588,22 +587,22 @@ export async function checkAllAwaitingStepsFinishedWithReturnParams(
|
|
|
588
587
|
* @param {string} pendingStepId - The ID of the pending step.
|
|
589
588
|
* @returns {Promise<boolean>} True if operations completed successfully.
|
|
590
589
|
*/
|
|
591
|
-
|
|
592
|
-
_izContext.logger.debug(
|
|
593
|
-
pendingStepId
|
|
590
|
+
async function clearAllAwaitingSteps(_izContext, pendingStepId) {
|
|
591
|
+
_izContext.logger.debug('[Lib:clearAllAwaitingSteps] Input parameters', {
|
|
592
|
+
pendingStepId
|
|
594
593
|
});
|
|
595
594
|
|
|
596
595
|
const awaitingStepItems = await _queryAwaitingStepsByPendingStepId(
|
|
597
596
|
_izContext,
|
|
598
|
-
pendingStepId
|
|
597
|
+
pendingStepId
|
|
599
598
|
);
|
|
600
599
|
const tableSteps = dynamodbSharedLib.tableName(
|
|
601
600
|
_izContext,
|
|
602
|
-
|
|
601
|
+
'AwaitingMultipleSteps'
|
|
603
602
|
);
|
|
604
603
|
const tablePending = dynamodbSharedLib.tableName(
|
|
605
604
|
_izContext,
|
|
606
|
-
|
|
605
|
+
'AwaitingMultipleStepByPending'
|
|
607
606
|
);
|
|
608
607
|
|
|
609
608
|
await Promise.all(
|
|
@@ -611,14 +610,14 @@ export async function clearAllAwaitingSteps(_izContext, pendingStepId) {
|
|
|
611
610
|
({ awaitingStepId, pendingStepId: itemPendingStepId }) => [
|
|
612
611
|
dynamodbSharedLib.deleteItem(_izContext, tableSteps, {
|
|
613
612
|
awaitingStepId,
|
|
614
|
-
pendingStepId: itemPendingStepId
|
|
613
|
+
pendingStepId: itemPendingStepId
|
|
615
614
|
}),
|
|
616
615
|
dynamodbSharedLib.deleteItem(_izContext, tablePending, {
|
|
617
616
|
awaitingStepId,
|
|
618
|
-
pendingStepId: itemPendingStepId
|
|
619
|
-
})
|
|
620
|
-
]
|
|
621
|
-
)
|
|
617
|
+
pendingStepId: itemPendingStepId
|
|
618
|
+
})
|
|
619
|
+
]
|
|
620
|
+
)
|
|
622
621
|
);
|
|
623
622
|
|
|
624
623
|
return true;
|
|
@@ -633,16 +632,16 @@ export async function clearAllAwaitingSteps(_izContext, pendingStepId) {
|
|
|
633
632
|
* @param {Array<any>} [errorsFound=[]] - List of errors.
|
|
634
633
|
* @returns {Promise<void>}
|
|
635
634
|
*/
|
|
636
|
-
|
|
635
|
+
async function removeAwaitingMultipleStep(
|
|
637
636
|
_izContext,
|
|
638
637
|
awaitingStepId,
|
|
639
638
|
pendingStepId,
|
|
640
|
-
errorsFound = []
|
|
639
|
+
errorsFound = []
|
|
641
640
|
) {
|
|
642
|
-
_izContext.logger.debug(
|
|
641
|
+
_izContext.logger.debug('[Lib:removeAwaitingMultipleStep] Input parameters', {
|
|
643
642
|
awaitingStepId,
|
|
644
643
|
pendingStepId,
|
|
645
|
-
errorsFound
|
|
644
|
+
errorsFound
|
|
646
645
|
});
|
|
647
646
|
|
|
648
647
|
if (!awaitingStepId || !pendingStepId) {
|
|
@@ -656,9 +655,9 @@ export async function removeAwaitingMultipleStep(
|
|
|
656
655
|
const promises = [
|
|
657
656
|
dynamodbSharedLib.deleteItem(
|
|
658
657
|
_izContext,
|
|
659
|
-
dynamodbSharedLib.tableName(_izContext,
|
|
660
|
-
keys
|
|
661
|
-
)
|
|
658
|
+
dynamodbSharedLib.tableName(_izContext, 'AwaitingMultipleSteps'),
|
|
659
|
+
keys
|
|
660
|
+
)
|
|
662
661
|
];
|
|
663
662
|
|
|
664
663
|
if (errorsFound.length === 0) {
|
|
@@ -667,10 +666,10 @@ export async function removeAwaitingMultipleStep(
|
|
|
667
666
|
_izContext,
|
|
668
667
|
dynamodbSharedLib.tableName(
|
|
669
668
|
_izContext,
|
|
670
|
-
|
|
669
|
+
'AwaitingMultipleStepByPending'
|
|
671
670
|
),
|
|
672
|
-
keys
|
|
673
|
-
)
|
|
671
|
+
keys
|
|
672
|
+
)
|
|
674
673
|
);
|
|
675
674
|
}
|
|
676
675
|
|
|
@@ -684,10 +683,10 @@ export async function removeAwaitingMultipleStep(
|
|
|
684
683
|
* @param {string} parentFlowId - The ID of the parent flow.
|
|
685
684
|
* @returns {Promise<Object>} Status object containing completion details.
|
|
686
685
|
*/
|
|
687
|
-
|
|
686
|
+
async function completeAction(
|
|
688
687
|
_izContext,
|
|
689
688
|
parentFlowId,
|
|
690
|
-
prefix =
|
|
689
|
+
prefix = '',
|
|
691
690
|
returnValue = {},
|
|
692
691
|
errorsFound = [],
|
|
693
692
|
settings = { checkIsAllError: false }
|
|
@@ -698,17 +697,14 @@ export async function completeAction(
|
|
|
698
697
|
});
|
|
699
698
|
|
|
700
699
|
try {
|
|
701
|
-
const {pendingStepId} = await findPendingStepAwaitingMultipleSteps(
|
|
700
|
+
const { pendingStepId } = await findPendingStepAwaitingMultipleSteps(
|
|
702
701
|
_izContext,
|
|
703
|
-
createAwaitingStepId(
|
|
704
|
-
parentFlowId,
|
|
705
|
-
prefix
|
|
706
|
-
)
|
|
702
|
+
createAwaitingStepId(parentFlowId, prefix)
|
|
707
703
|
);
|
|
708
704
|
|
|
709
705
|
if (!pendingStepId) {
|
|
710
706
|
_izContext.logger.warn(
|
|
711
|
-
`No pending step found for awaitingStepId: ${awaitingStepId}
|
|
707
|
+
`No pending step found for awaitingStepId: ${awaitingStepId}`
|
|
712
708
|
);
|
|
713
709
|
return { returnValue, errorsFound };
|
|
714
710
|
}
|
|
@@ -718,14 +714,11 @@ export async function completeAction(
|
|
|
718
714
|
collectedReturnValueByAwaitingStepId,
|
|
719
715
|
collectedErrors,
|
|
720
716
|
returnValues,
|
|
721
|
-
additionalAttributes
|
|
717
|
+
additionalAttributes
|
|
722
718
|
} = await checkAllAwaitingStepsFinishedWithReturnParams(
|
|
723
719
|
_izContext,
|
|
724
720
|
pendingStepId,
|
|
725
|
-
createAwaitingStepId(
|
|
726
|
-
parentFlowId,
|
|
727
|
-
prefix
|
|
728
|
-
),
|
|
721
|
+
createAwaitingStepId(parentFlowId, prefix),
|
|
729
722
|
errorsFound,
|
|
730
723
|
returnValue,
|
|
731
724
|
{ checkIsAllError: settings.checkIsAllError }
|
|
@@ -750,15 +743,17 @@ export async function completeAction(
|
|
|
750
743
|
await dynamodbSharedLib.tableName(
|
|
751
744
|
_izContext,
|
|
752
745
|
record.tableName,
|
|
753
|
-
record.serviceTag
|
|
746
|
+
record.serviceTag
|
|
754
747
|
),
|
|
755
748
|
{
|
|
756
|
-
...record.objInstanceFull.identifiers
|
|
757
|
-
...record.objInstanceFull.fields,
|
|
749
|
+
...record.objInstanceFull.identifiers
|
|
758
750
|
},
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
751
|
+
{
|
|
752
|
+
...record.objInstanceFull.fields
|
|
753
|
+
}
|
|
754
|
+
)
|
|
755
|
+
)
|
|
756
|
+
)
|
|
762
757
|
);
|
|
763
758
|
}
|
|
764
759
|
|
|
@@ -774,3 +769,16 @@ export async function completeAction(
|
|
|
774
769
|
_izContext.logger.error(err);
|
|
775
770
|
}
|
|
776
771
|
}
|
|
772
|
+
|
|
773
|
+
export {
|
|
774
|
+
createAwaitingMultipleSteps,
|
|
775
|
+
updateAwaitingMultipleStep,
|
|
776
|
+
findPendingStepAwaitingMultipleSteps,
|
|
777
|
+
findPendingStepsAwaitingMultipleSteps,
|
|
778
|
+
findPendingStepIdAwaitingMultipleSteps,
|
|
779
|
+
findAwaitingMultipleStepByPending,
|
|
780
|
+
checkAllAwaitingStepsFinishedWithReturnParams,
|
|
781
|
+
clearAllAwaitingSteps,
|
|
782
|
+
removeAwaitingMultipleStep,
|
|
783
|
+
completeAction
|
|
784
|
+
};
|
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
|
+
};
|