@izara_project/izara-core-library-asynchronous-flow 1.0.9 → 1.0.11

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@izara_project/izara-core-library-asynchronous-flow",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "description": "Shared asynchronous flow logic",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -302,8 +302,8 @@ async function checkAllAwaitingStepsFinished(
302
302
  byPendingTableName = "AwaitingMultipleStepByPending"
303
303
  // indexName = ''
304
304
  ) {
305
- let remaining;
306
- [remaining, errorsFound] = await this.checkAllAwaitingStepsFinishedWithError(
305
+
306
+ let remaining = await checkAllAwaitingStepsFinishedWithError(
307
307
  _izContext,
308
308
  pendingStepId,
309
309
  currentAwaitingStepId,
@@ -315,7 +315,8 @@ async function checkAllAwaitingStepsFinished(
315
315
  }
316
316
 
317
317
 
318
- module.exports.checkAllAwaitingStepsFinishedWithError = async (
318
+
319
+ async function checkAllAwaitingStepsFinishedWithError(
319
320
  _izContext,
320
321
  pendingStepId,
321
322
  currentAwaitingStepId = null,
@@ -323,7 +324,7 @@ module.exports.checkAllAwaitingStepsFinishedWithError = async (
323
324
  tableName = 'AwaitingMultipleSteps',
324
325
  byPendingTableName = "AwaitingMultipleStepByPending"
325
326
  // indexName = ''
326
- ) => {
327
+ ) {
327
328
  _izContext.logger.debug("Lib:checkAllAwaitingStepsFinishedWithError", {
328
329
  pendingStepId: pendingStepId,
329
330
  currentAwaitingStepId: currentAwaitingStepId,
@@ -381,11 +382,11 @@ module.exports.checkAllAwaitingStepsFinishedWithError = async (
381
382
  }
382
383
  // if any record found not set to complete then there are steps not yet finished
383
384
  if (!listPendingStepIds.Items[idx].complete) {
384
- return [false, errorsFound];
385
+ return false;
385
386
  }
386
387
  }
387
388
 
388
- return [true, errorsFound]; // all passed
389
+ return true; // all passed
389
390
 
390
391
 
391
392
  // // mark currentAwaitingStepId as complete, this is done to protect against race condition in between checking all complete
@@ -513,6 +514,7 @@ async function removeAwaitingMultipleStep(
513
514
  _izContext,
514
515
  awaitingStepId,
515
516
  pendingStepId,
517
+ errorsFound = [],
516
518
  tableName = "AwaitingMultipleSteps",
517
519
  byPendingTableName = "AwaitingMultipleStepByPending"
518
520
  ) {
@@ -525,11 +527,20 @@ async function removeAwaitingMultipleStep(
525
527
 
526
528
  let promiseArray = []
527
529
 
530
+
528
531
  let keyValues = {
529
532
  awaitingStepId: awaitingStepId,
530
533
  pendingStepId: pendingStepId
531
534
  }
532
- _izContext.logger.debug('deleting ... ', keyValues);
535
+
536
+ let keyValuesForByPending = {
537
+ pendingStepId: pendingStepId,
538
+ awaitingStepId: awaitingStepId
539
+ }
540
+ _izContext.logger.debug('deleting ... ', {
541
+ keyValues,
542
+ keyValuesForByPending
543
+ });
533
544
 
534
545
  _izContext.logger.debug(`delete item in dynamodb AwaitingMultipleSteps ==> awaitingStepId:${keyValues.awaitingStepId}`)
535
546
  promiseArray.push(
@@ -538,15 +549,15 @@ async function removeAwaitingMultipleStep(
538
549
  await dynamodbSharedLib.tableName(_izContext, tableName),
539
550
  keyValues
540
551
  ));
541
-
542
- _izContext.logger.debug(`delete item in dynamodb AwaitingMultipleStepByPending ==> awaitingStepId:${keyValues.awaitingStepId}`)
543
- promiseArray.push(
544
- dynamodbSharedLib.deleteItem(
545
- _izContext,
546
- await dynamodbSharedLib.tableName(_izContext, byPendingTableName),
547
- keyValues
548
- ));
549
-
552
+ if (errorsFound.length == 0) {
553
+ _izContext.logger.debug(`delete item in dynamodb AwaitingMultipleStepByPending ==> awaitingStepId:${keyValues.awaitingStepId}`)
554
+ promiseArray.push(
555
+ dynamodbSharedLib.deleteItem(
556
+ _izContext,
557
+ await dynamodbSharedLib.tableName(_izContext, byPendingTableName),
558
+ keyValuesForByPending
559
+ ));
560
+ }
550
561
  await Promise.all(promiseArray);
551
562
 
552
563
  }
@@ -571,7 +582,7 @@ async function removeAwaitingStepWithCheckUniqueRequestId(
571
582
  {
572
583
  type: "logical",
573
584
  comparison: "equals",
574
- lhsAttribute: this.createFieldNameUniqueRequestId(prefix),
585
+ lhsAttribute: createFieldNameUniqueRequestId(prefix),
575
586
  rhsReference: "checkUniqueRequestId"
576
587
  },
577
588
  ]
@@ -629,7 +640,7 @@ async function checkUniqueRequestProcessing(
629
640
  }
630
641
 
631
642
  // add prefix
632
- uniqueRequestIdFieldName = this.createFieldNameUniqueRequestId(
643
+ uniqueRequestIdFieldName = createFieldNameUniqueRequestId(
633
644
  prefix,
634
645
  uniqueRequestIdFieldName
635
646
  );
@@ -723,7 +734,7 @@ async function checkTimeCacheComplete(
723
734
  timeCacheComplete,
724
735
  prefix
725
736
  ) {
726
- let [returnValue, newTimeCacheComplete, uniqueRequestId] = await this.checkAndGetTimeCacheComplete(
737
+ let [returnValue, newTimeCacheComplete, uniqueRequestId] = await checkAndGetTimeCacheComplete(
727
738
  _izContext,
728
739
  fullMainTableName,
729
740
  keyValues,
@@ -746,9 +757,9 @@ async function checkAndGetTimeCacheComplete(
746
757
  prefix: prefix
747
758
  });
748
759
 
749
- let uniqueRequestIdFieldName = this.createFieldNameUniqueRequestId('cache');
750
- let cacheCompleteFieldName = this.createFieldNameCacheComplete(prefix);
751
- let statusFieldName = this.createFieldNameStatus(prefix);
760
+ let uniqueRequestIdFieldName = createFieldNameUniqueRequestId('cache');
761
+ let cacheCompleteFieldName = createFieldNameCacheComplete(prefix);
762
+ let statusFieldName = createFieldNameStatus(prefix);
752
763
 
753
764
  let getTimeCacheComplete = await dynamodbSharedLib.getItem(
754
765
  _izContext,
@@ -945,6 +956,7 @@ module.exports = {
945
956
  // AwaitingMultipleSteps functions
946
957
  createAwaitingMultipleStepsWithAdditionalAttributes,
947
958
  createAwaitingMultipleSteps,
959
+ checkAllAwaitingStepsFinishedWithError,
948
960
  checkAllAwaitingStepsFinished,
949
961
  clearAllAwaitingSteps,
950
962
  removeAwaitingMultipleStep,