From f1fac6ca660db22d178303866ea93be070c7d5c4 Mon Sep 17 00:00:00 2001 From: Armen Zambrano G Date: Fri, 7 Sep 2018 09:36:53 -0400 Subject: [PATCH] Issue #132 - Script fetching Nimbledroid data should return a proper exit code We also add more verbosity and build the project before calling the script to reflect code changes to the script. --- package.json | 2 +- src/scripts/fetchNimbledroidData.js | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index cd538f8..45f3dbc 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "start:debugger": "neutrino build && node --inspect .", "precommit": "lint-staged", "heroku-postbuild": "npm run build", - "fetchNimbledroidData": "node build/nimbledroid.js" + "fetchNimbledroidData": "neutrino build && node build/nimbledroid.js" }, "lint-staged": { "*.js": [ diff --git a/src/scripts/fetchNimbledroidData.js b/src/scripts/fetchNimbledroidData.js index fde5946..74cc4aa 100644 --- a/src/scripts/fetchNimbledroidData.js +++ b/src/scripts/fetchNimbledroidData.js @@ -35,6 +35,8 @@ const storeProfilingRunIfMissing = async (profilingRunData) => { if (!cached) { console.log(`Storing ${key}`); await redisClient.set(key, JSON.stringify(profilingRunData)); + } else { + console.log(`The key is already in the cache (${key})`); } } }; @@ -48,17 +50,20 @@ const fetchData = async productName => nimbledroidClient.getNimbledroidData(productName); const main = async () => { + let errorCode = -1; console.log('Fetching each product can take between 20-40 seconds.'); try { await Promise.all(['klar', 'focus'].map(async (productName) => { console.log(`Fetching ${productName}`); const productData = await fetchData(productName); + console.log(`Storing ${productName}`); await storeDataInRedis(productData); })); + errorCode = 0; } catch (e) { console.error(e); } finally { - process.exit(); + process.exit(errorCode); } };