@izara_project/izara-core-library-asynchronous-flow 1.0.7 → 1.0.8

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/index.js CHANGED
@@ -38,6 +38,7 @@ module.exports = {
38
38
  createAwaitingStep: asyncFlowSharedLib.createAwaitingStep,
39
39
  findPendingStepIdsAwaitingStep: asyncFlowSharedLib.findPendingStepIdsAwaitingStep,
40
40
  findPendingStepsAwaitingStep: asyncFlowSharedLib.findPendingStepsAwaitingStep,
41
+ findPendingStepAwaitingStep: asyncFlowSharedLib.findPendingStepAwaitingStep,
41
42
 
42
43
  // Checking and clearing steps
43
44
  checkAllAwaitingStepsFinished: asyncFlowSharedLib.checkAllAwaitingStepsFinished,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@izara_project/izara-core-library-asynchronous-flow",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "Shared asynchronous flow logic",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -269,6 +269,27 @@ async function findPendingStepsAwaitingStep(
269
269
  _izContext.logger.debug("Record of awaitingStepId", listPendingSteps)
270
270
  return listPendingSteps.Items;
271
271
  }
272
+ async function findPendingStepAwaitingStep(
273
+ _izContext,
274
+ awaitingStepId,
275
+ tableName = "AwaitingStep"
276
+ ) {
277
+
278
+ let listPendingSteps = await dynamodbSharedLib.query(
279
+ _izContext,
280
+ await dynamodbSharedLib.tableName(_izContext, tableName),
281
+ {
282
+ awaitingStepId: awaitingStepId
283
+ }
284
+ );
285
+ _izContext.logger.debug("Record of awaitingStepId", listPendingSteps)
286
+
287
+ if (listPendingSteps.length !== 1) {
288
+ throw new NoRetryError("listPendingSteps not equals 1")
289
+ }
290
+
291
+ return listPendingSteps.Items[0];
292
+ }
272
293
 
273
294
 
274
295
 
@@ -276,11 +297,33 @@ async function checkAllAwaitingStepsFinished(
276
297
  _izContext,
277
298
  pendingStepId,
278
299
  currentAwaitingStepId = null,
300
+ errorsFound = [],
279
301
  tableName = 'AwaitingMultipleSteps',
280
302
  byPendingTableName = "AwaitingMultipleStepByPending"
281
303
  // indexName = ''
282
304
  ) {
283
- _izContext.logger.debug("Lib:checkAllAwaitingStepsFinished", {
305
+ let [remaining, errorsFound] = await this.checkAllAwaitingStepsFinishedWithError(
306
+ _izContext,
307
+ pendingStepId,
308
+ currentAwaitingStepId,
309
+ errorsFound,
310
+ tableName,
311
+ byPendingTableName
312
+ );
313
+ return remaining;
314
+ }
315
+
316
+
317
+ module.exports.checkAllAwaitingStepsFinishedWithError = async (
318
+ _izContext,
319
+ pendingStepId,
320
+ currentAwaitingStepId = null,
321
+ errorsFound = [],
322
+ tableName = 'AwaitingMultipleSteps',
323
+ byPendingTableName = "AwaitingMultipleStepByPending"
324
+ // indexName = ''
325
+ ) => {
326
+ _izContext.logger.debug("Lib:checkAllAwaitingStepsFinishedWithError", {
284
327
  pendingStepId: pendingStepId,
285
328
  currentAwaitingStepId: currentAwaitingStepId,
286
329
  tableName: tableName,
@@ -311,7 +354,8 @@ async function checkAllAwaitingStepsFinished(
311
354
  awaitingStepId: currentAwaitingStepId
312
355
  },
313
356
  {
314
- complete: true
357
+ complete: true,
358
+ errorsFound: errorsFound
315
359
  },
316
360
  );
317
361
 
@@ -328,16 +372,19 @@ async function checkAllAwaitingStepsFinished(
328
372
  );
329
373
  for (let idx = 0; idx < listPendingStepIds.Items.length; idx++) {
330
374
 
375
+ // if have error found return errorfound
376
+ // wrap function
377
+
331
378
  if (currentAwaitingStepId && listPendingStepIds.Items[idx].awaitingStepId == currentAwaitingStepId) {
332
379
  continue;
333
380
  }
334
381
  // if any record found not set to complete then there are steps not yet finished
335
382
  if (!listPendingStepIds.Items[idx].complete) {
336
- return false;
383
+ return [false, errorsFound];
337
384
  }
338
385
  }
339
386
 
340
- return true;
387
+ return [true, errorsFound]; // all passed
341
388
 
342
389
 
343
390
  // // mark currentAwaitingStepId as complete, this is done to protect against race condition in between checking all complete
@@ -384,6 +431,8 @@ async function checkAllAwaitingStepsFinished(
384
431
  // return true;
385
432
  }
386
433
 
434
+
435
+
387
436
  async function clearAllAwaitingSteps(
388
437
  _izContext,
389
438
  pendingStepId,
@@ -902,6 +951,7 @@ module.exports = {
902
951
  // AwaitingStep functions
903
952
  createAwaitingStep,
904
953
  findPendingStepIdsAwaitingStep,
954
+ findPendingStepAwaitingStep,
905
955
  findPendingStepsAwaitingStep,
906
956
  removeAwaitingStep,
907
957
  removeAwaitingStepWithCheckUniqueRequestId,