Skip to content

Commit

Permalink
better error handling in worker job
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosQ96 committed Jan 27, 2025
1 parent 7797caa commit 73d6cfa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/services/cronJobs/syncEstimatedClusterMatchingJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions src/workers/cocm/estimatedClusterMatchingWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type EstimatedClusterMatchingWorker =
const worker: EstimatedClusterMatchingWorker = {
async fetchEstimatedClusterMatching(matchingDataInput: any) {
logger.debug('fetchEstimatedClusterMatching() has been called');
try {
const matchingData =

Check failure on line 19 in src/workers/cocm/estimatedClusterMatchingWorker.ts

View workflow job for this annotation

GitHub Actions / test

Insert `··`

Check failure on line 19 in src/workers/cocm/estimatedClusterMatchingWorker.ts

View workflow job for this annotation

GitHub Actions / test

Insert `··`
await getClusterMatchingAdapter().fetchEstimatedClusterMatchings(

Check failure on line 20 in src/workers/cocm/estimatedClusterMatchingWorker.ts

View workflow job for this annotation

GitHub Actions / test

Insert `··`

Check failure on line 20 in src/workers/cocm/estimatedClusterMatchingWorker.ts

View workflow job for this annotation

GitHub Actions / test

Insert `··`
matchingDataInput,

Check failure on line 21 in src/workers/cocm/estimatedClusterMatchingWorker.ts

View workflow job for this annotation

GitHub Actions / test

Insert `··`

Check failure on line 21 in src/workers/cocm/estimatedClusterMatchingWorker.ts

View workflow job for this annotation

GitHub Actions / test

Insert `··`
Expand All @@ -24,6 +25,13 @@ const worker: EstimatedClusterMatchingWorker = {
String(matchingData),

Check failure on line 25 in src/workers/cocm/estimatedClusterMatchingWorker.ts

View workflow job for this annotation

GitHub Actions / test

Insert `··`

Check failure on line 25 in src/workers/cocm/estimatedClusterMatchingWorker.ts

View workflow job for this annotation

GitHub Actions / test

Insert `··`
);

Check failure on line 26 in src/workers/cocm/estimatedClusterMatchingWorker.ts

View workflow job for this annotation

GitHub Actions / test

Insert `··`

Check failure on line 26 in src/workers/cocm/estimatedClusterMatchingWorker.ts

View workflow job for this annotation

GitHub Actions / test

Insert `··`
return matchingData;

Check failure on line 27 in src/workers/cocm/estimatedClusterMatchingWorker.ts

View workflow job for this annotation

GitHub Actions / test

Insert `··`

Check failure on line 27 in src/workers/cocm/estimatedClusterMatchingWorker.ts

View workflow job for this annotation

GitHub Actions / test

Insert `··`
} catch (e) {
logger.error(

Check failure on line 29 in src/workers/cocm/estimatedClusterMatchingWorker.ts

View workflow job for this annotation

GitHub Actions / test

Replace `⏎········'fetchEstimatedClusterMatching()·did·not·work.·Error:·',⏎········e⏎······` with `'fetchEstimatedClusterMatching()·did·not·work.·Error:·',·e`

Check failure on line 29 in src/workers/cocm/estimatedClusterMatchingWorker.ts

View workflow job for this annotation

GitHub Actions / test

Replace `⏎········'fetchEstimatedClusterMatching()·did·not·work.·Error:·',⏎········e⏎······` with `'fetchEstimatedClusterMatching()·did·not·work.·Error:·',·e`
'fetchEstimatedClusterMatching() did not work. Error: ',
e
);
return;
}
},

async updateEstimatedClusterMatching(qfRoundId: number, matchingData: any) {
Expand Down

0 comments on commit 73d6cfa

Please sign in to comment.