From b9eb0f938cb0bc3bad1763ce79bcb4587737e2d5 Mon Sep 17 00:00:00 2001 From: Ying Wei Loke Date: Fri, 31 Mar 2017 15:07:49 -0400 Subject: [PATCH 1/2] m: fix s3-util hardcode bucket name --- lib/utils/s3-util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/utils/s3-util.js b/lib/utils/s3-util.js index 62b75d1..0fa5f2a 100644 --- a/lib/utils/s3-util.js +++ b/lib/utils/s3-util.js @@ -64,7 +64,7 @@ exports.uploadDir = (AWS, params) => { (f) => new Promise((resolve, reject) => { new AWS.S3().upload( { - Bucket: 'sheepcd-s3root-lmncd', + Bucket: params.s3Params.Bucket, Key: path.join( params.s3Params.Prefix, path.relative(params.localDir, f) From fc3f99747c8c411f507068bd259d5a525a93b47b Mon Sep 17 00:00:00 2001 From: Ying Wei Loke Date: Fri, 31 Mar 2017 15:14:19 -0400 Subject: [PATCH 2/2] m: fix promise-util resolves promise earlier than it should --- lib/utils/promise-util.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/utils/promise-util.js b/lib/utils/promise-util.js index be4652a..36209e2 100644 --- a/lib/utils/promise-util.js +++ b/lib/utils/promise-util.js @@ -45,6 +45,14 @@ exports.mapF = function(tasks, worker, parallelCnt) { return new Promise((resolve, reject) => { const f = () => { + // rely on worker.then(f) to check this condition + // instead of right after the while loop + // to prevent resolving the promise before the worker is done. + // This fixes parent promise misses the child promise rejection + if (nextTask === tasks.length) { + resolve(res); + } + while (runningCnt < parallelCnt && nextTask < tasks.length) { runningCnt += 1; @@ -61,10 +69,6 @@ exports.mapF = function(tasks, worker, parallelCnt) { reject(ex); }); } - - if (nextTask === tasks.length) { - resolve(res); - } }; f();