From 5455a5d52df536047215fdcbc0008ff048565ec6 Mon Sep 17 00:00:00 2001 From: Armen Zambrano Date: Tue, 26 Nov 2019 16:09:58 -0500 Subject: [PATCH] Fix #71 - Fetch Nimbledroid data from nimbledroid-admin user (#73) * Fix #71 - Fetch Nimbledroid data from nimbledroid-admin user * Handle Profiled status and empty data Until now, all profiled results from Nimbledroid had a status of `Failure`. It seems they fixed the bug and we now have the `Profiled` status being used. I've noticed that some of the end points return empty data and we now handle it. --- src/configuration.js | 2 +- src/scripts/fetchNimbledroidData.js | 8 +++++--- src/utils/NimbledroidClient/index.js | 10 +++++++++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/configuration.js b/src/configuration.js index 64f3821..fbb1244 100644 --- a/src/configuration.js +++ b/src/configuration.js @@ -1,5 +1,5 @@ const config = { - nimbledroidApiUrl: 'https://nimbledroid.com/api/v2/users/npark@mozilla.com/apps', + nimbledroidApiUrl: 'https://nimbledroid.com/api/v2/users/nimbledroid-admin@mozilla.com/apps', repoUrl: 'https://github.com/mozilla/firefox-health-backend', }; diff --git a/src/scripts/fetchNimbledroidData.js b/src/scripts/fetchNimbledroidData.js index 98df606..3981304 100644 --- a/src/scripts/fetchNimbledroidData.js +++ b/src/scripts/fetchNimbledroidData.js @@ -35,7 +35,7 @@ const storeProfilingRunIfMissing = async (profilingRunData) => { // e.g. cache:https://nimbledroid.com/api/v2/users/npark@mozilla.com/apps/org.mozilla.klar/apks/103 const key = `cache:${url}`; // The status 'Failed' means 'completed' in the Nimbledroid API - if (status === 'Failed') { + if (status === 'Failed' || status === 'Profiled') { const cached = await redisClient.get(key); if (!cached) { debugLog(`Storing ${key}`); @@ -66,8 +66,10 @@ const main = async () => { ].map(async (productName) => { infoLog(`Fetching ${productName}`); const productData = await fetchData(productName); - infoLog(`Storing ${productName}`); - await storeDataInRedis(productData); + if (productData.length > 0) { + infoLog(`Storing ${productName}`); + await storeDataInRedis(productData); + } })); errorCode = 0; } catch (e) { diff --git a/src/utils/NimbledroidClient/index.js b/src/utils/NimbledroidClient/index.js index 0fe2ee6..1f42513 100644 --- a/src/utils/NimbledroidClient/index.js +++ b/src/utils/NimbledroidClient/index.js @@ -1,6 +1,9 @@ +import debug from 'debug'; import fetchJson from '../../fetch/json'; import config from '../../configuration'; +const errorLog = debug('script:error'); + const apiUrl = product => `${config.nimbledroidApiUrl}/${product}/apks`; const generateAuthKey = (email, apiKey) => ( @@ -29,7 +32,8 @@ class NimbledroidHandler { } async fetchData(product) { - return fetchJson( + const url = apiUrl(product); + const data = await fetchJson( apiUrl(product), { method: 'GET', @@ -37,6 +41,10 @@ class NimbledroidHandler { ttl: 30 * 60, // 30 minutes }, ); + if (data.length === 0) { + errorLog(`There was nothing to be stored from ${url}`); + } + return data; } generateAuthHeaders() {