From 73d6cfad55c00f684259a6d2a31fa27c83178df4 Mon Sep 17 00:00:00 2001 From: Carlos Date: Mon, 27 Jan 2025 12:37:39 +0100 Subject: [PATCH] better error handling in worker job --- .../syncEstimatedClusterMatchingJob.ts | 34 +++++++++---------- .../cocm/estimatedClusterMatchingWorker.ts | 8 +++++ 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/services/cronJobs/syncEstimatedClusterMatchingJob.ts b/src/services/cronJobs/syncEstimatedClusterMatchingJob.ts index c87f29099..cb86acc3c 100644 --- a/src/services/cronJobs/syncEstimatedClusterMatchingJob.ts +++ b/src/services/cronJobs/syncEstimatedClusterMatchingJob.ts @@ -66,26 +66,26 @@ export const fetchAndUpdateClusterEstimatedMatching = async () => { new Worker('../../workers/cocm/estimatedClusterMatchingWorker'), ); - const activeQfRound = await findActiveQfRound(); - if (!activeQfRound?.id) return; + try { + const activeQfRound = await findActiveQfRound(); + if (!activeQfRound?.id) return; - const clusterMatchingDonations = await exportClusterMatchingDonationsFormat( - activeQfRound?.id, - ); - if (!clusterMatchingDonations || clusterMatchingDonations?.length === 0) - return; + const clusterMatchingDonations = await exportClusterMatchingDonationsFormat( + activeQfRound?.id, + ); + if (!clusterMatchingDonations || clusterMatchingDonations?.length === 0) + return; - const matchingDataInput = { - votes_data: clusterMatchingDonations, - strategy: defaultMatchingStrategy, - min_donation_threshold_amount: activeQfRound.minimumValidUsdValue, - matching_cap_amount: - activeQfRound.allocatedFundUSD * activeQfRound.maximumReward, - matching_amount: activeQfRound.allocatedFundUSD, - passport_threshold: activeQfRound.minimumPassportScore, - }; + const matchingDataInput = { + votes_data: clusterMatchingDonations, + strategy: defaultMatchingStrategy, + min_donation_threshold_amount: activeQfRound.minimumValidUsdValue, + matching_cap_amount: + activeQfRound.allocatedFundUSD * activeQfRound.maximumReward, + matching_amount: activeQfRound.allocatedFundUSD, + passport_threshold: activeQfRound.minimumPassportScore, + }; - try { // Fetch from python api cluster matching const matchingData = await matchingWorker.fetchEstimatedClusterMatching(matchingDataInput); diff --git a/src/workers/cocm/estimatedClusterMatchingWorker.ts b/src/workers/cocm/estimatedClusterMatchingWorker.ts index a2ece8973..50530a1a2 100644 --- a/src/workers/cocm/estimatedClusterMatchingWorker.ts +++ b/src/workers/cocm/estimatedClusterMatchingWorker.ts @@ -15,6 +15,7 @@ export type EstimatedClusterMatchingWorker = const worker: EstimatedClusterMatchingWorker = { async fetchEstimatedClusterMatching(matchingDataInput: any) { logger.debug('fetchEstimatedClusterMatching() has been called'); + try { const matchingData = await getClusterMatchingAdapter().fetchEstimatedClusterMatchings( matchingDataInput, @@ -24,6 +25,13 @@ const worker: EstimatedClusterMatchingWorker = { String(matchingData), ); return matchingData; + } catch (e) { + logger.error( + 'fetchEstimatedClusterMatching() did not work. Error: ', + e + ); + return; + } }, async updateEstimatedClusterMatching(qfRoundId: number, matchingData: any) {