diff --git a/packages/api/src/jobs/update_home.ts b/packages/api/src/jobs/update_home.ts index b57f71adc..e161f967b 100644 --- a/packages/api/src/jobs/update_home.ts +++ b/packages/api/src/jobs/update_home.ts @@ -248,7 +248,7 @@ const rankCandidates = async ( const scores = await scoreClient.getScores(data) // update scores for candidates candidates.forEach((item) => { - item.score = scores[item.id]['score'] || 0 + item.score = scores[item.id].score || 0 }) // rank candidates by score in descending order diff --git a/packages/api/src/services/score.ts b/packages/api/src/services/score.ts index aed8f4b7b..92428cd40 100644 --- a/packages/api/src/services/score.ts +++ b/packages/api/src/services/score.ts @@ -75,9 +75,9 @@ class ScoreClientImpl implements ScoreClient { } async getScores(data: ScoreApiRequestBody): Promise { - try { - const start = Date.now() + const start = Date.now() + try { const response = await axios.post(this.apiUrl, data, { headers: { 'Content-Type': 'application/json', @@ -85,9 +85,6 @@ class ScoreClientImpl implements ScoreClient { timeout: 5000, }) - const duration = (Date.now() - start) / 1000 // in seconds - latency.observe(duration) - return response.data } catch (error) { logError(error) @@ -96,6 +93,9 @@ class ScoreClientImpl implements ScoreClient { return { [Object.keys(data.items)[0]]: { score: 0 }, } + } finally { + const duration = (Date.now() - start) / 1000 // in seconds + latency.observe(duration) } } }