@izara_project/izara-core-library-asynchronous-flow 1.0.29 → 1.0.31
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 +1 -1
- package/src/awaitingMultipleSteps.js +29 -17
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.31",
|
|
7
7
|
"description": "Shared asynchronous flow logic",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"main": "index.js",
|
|
@@ -26,6 +26,20 @@ import { identifierUuid } from '@izara_project/izara-shared-core';
|
|
|
26
26
|
// One pendingStepId can have multiple awaitingStepIds it is awaiting
|
|
27
27
|
// logic can prepend any prefix to awaitingStepId if want to be share one table and differentiate different external step ids
|
|
28
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Create multiple parent Ids.
|
|
31
|
+
* @async
|
|
32
|
+
* @param {number} count - The number of parent Ids to create.
|
|
33
|
+
* @param {string} [prefix=''] - The prefix to prepend to the parent Ids.
|
|
34
|
+
* @returns {Promise<string[]>} The list of parent Ids created.
|
|
35
|
+
*/
|
|
36
|
+
export function createParendIds(count, prefix = '') {
|
|
37
|
+
return Array.from(
|
|
38
|
+
{ length: count },
|
|
39
|
+
() => (prefix ? `${prefix}_` : '') + identifierUuid.generate()
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
29
43
|
/**
|
|
30
44
|
* Create multiple awaiting records with optional per-record additional attributes.
|
|
31
45
|
* Writes to both "AwaitingMultipleSteps" and "AwaitingMultipleStepByPending".
|
|
@@ -199,7 +213,7 @@ export async function createAwaitingMultipleSteps(
|
|
|
199
213
|
* @async
|
|
200
214
|
* @param {IzContext} _izContext
|
|
201
215
|
* @param {string} pendingStepId
|
|
202
|
-
* @param {
|
|
216
|
+
* @param {string[]} parendIds
|
|
203
217
|
* @param {Object.<string, any>} [additionalAttributes={}] - Shared attributes stored for every step in AwaitingMultipleStepByPending.
|
|
204
218
|
* The same object is applied to all steps (caller cannot know the generated UUIDs beforehand).
|
|
205
219
|
* @returns {Promise<string[]>} The list of awaiting step IDs created.
|
|
@@ -207,25 +221,26 @@ export async function createAwaitingMultipleSteps(
|
|
|
207
221
|
export async function createNewAwaitingMultipleSteps(
|
|
208
222
|
_izContext,
|
|
209
223
|
pendingStepId,
|
|
210
|
-
|
|
224
|
+
parendIds,
|
|
211
225
|
additionalAttributes = {}
|
|
212
226
|
) {
|
|
213
|
-
_izContext.logger.debug(
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
227
|
+
_izContext.logger.debug(
|
|
228
|
+
'[Lib:AsyncFlow:createNewAwaitingMultipleSteps] Input: ',
|
|
229
|
+
{
|
|
230
|
+
pendingStepId,
|
|
231
|
+
countAwaitingMultipleSteps,
|
|
232
|
+
additionalAttributes
|
|
233
|
+
}
|
|
234
|
+
);
|
|
220
235
|
|
|
221
236
|
const promiseArray = [];
|
|
222
237
|
|
|
223
|
-
for (const
|
|
238
|
+
for (const parendId of parendIds) {
|
|
224
239
|
const attributesWhenCreate = {
|
|
225
|
-
awaitingStepId:
|
|
240
|
+
awaitingStepId: parendId,
|
|
226
241
|
pendingStepId: pendingStepId,
|
|
227
242
|
complete: false,
|
|
228
|
-
errorsFound: []
|
|
243
|
+
errorsFound: []
|
|
229
244
|
};
|
|
230
245
|
promiseArray.push(
|
|
231
246
|
dynamodbSharedLib.putItem(
|
|
@@ -258,7 +273,7 @@ export async function createNewAwaitingMultipleSteps(
|
|
|
258
273
|
|
|
259
274
|
await Promise.all(promiseArray);
|
|
260
275
|
|
|
261
|
-
return
|
|
276
|
+
return parendIds;
|
|
262
277
|
}
|
|
263
278
|
|
|
264
279
|
/**
|
|
@@ -399,7 +414,6 @@ export async function checkAllAwaitingStepsFinishedShared(
|
|
|
399
414
|
}
|
|
400
415
|
}
|
|
401
416
|
|
|
402
|
-
|
|
403
417
|
/**
|
|
404
418
|
* Same as checkAllAwaitingStepsFinished but writes errors/additionalAttributes to the *_ByPending row.
|
|
405
419
|
* @async
|
|
@@ -440,7 +454,6 @@ export async function checkAllAwaitingStepsFinished(
|
|
|
440
454
|
return true;
|
|
441
455
|
}
|
|
442
456
|
|
|
443
|
-
|
|
444
457
|
/**
|
|
445
458
|
* Checks if all awaiting steps for a pending step are complete after marking the current one as complete.
|
|
446
459
|
* If all steps are finished, returns an object with `isComplete: true` and the collected data.
|
|
@@ -527,7 +540,6 @@ export async function checkAllAwaitingStepsFinishedWithReturnParams(
|
|
|
527
540
|
};
|
|
528
541
|
}
|
|
529
542
|
|
|
530
|
-
|
|
531
543
|
/**
|
|
532
544
|
* Remove all awaiting records for a given pendingStepId from both tables.
|
|
533
545
|
* @async
|
|
@@ -648,4 +660,4 @@ export async function removeAwaitingMultipleStep(
|
|
|
648
660
|
);
|
|
649
661
|
}
|
|
650
662
|
await Promise.all(promiseArray);
|
|
651
|
-
}
|
|
663
|
+
}
|