Skip to content

Commit b8abe35

Browse files
Merge pull request #212 from GeneralMagicio/addSyncGitcoinScoreCronjob
add cron job to update Gitcoin scores
2 parents 5f550d9 + c03216d commit b8abe35

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

src/server/bootstrap.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ import { runSyncDataWithInverter } from '../services/cronJobs/syncDataWithInvert
6868
import { runSyncWithAnkrTransfers } from '../services/cronJobs/syncWithAnkrTransfers';
6969
import { runCheckPendingSwapsCronJob } from '../services/cronJobs/syncSwapTransactions';
7070
import { startTokenPriceCron } from '../services/cronJobs/tokenPriceCron';
71+
import { runUpdateGitcoinScoresJob } from '../services/cronJobs/updateGitcoinScoresJob';
7172

7273
Resource.validate = validate;
7374

@@ -167,6 +168,8 @@ export async function bootstrap() {
167168

168169
startTokenPriceCron();
169170

171+
runUpdateGitcoinScoresJob();
172+
170173
if (process.env.ENABLE_IMPORT_LOST_DONATIONS === 'true') {
171174
runSyncLostDonations();
172175
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { schedule } from 'node-cron';
2+
import config from '../../config';
3+
import { logger } from '../../utils/logger';
4+
import { User } from '../../entities/user';
5+
import { updateUserGitcoinScores } from '../userService';
6+
import {
7+
GITCOIN_PASSPORT_MIN_VALID_ANALYSIS_SCORE,
8+
GITCOIN_PASSPORT_MIN_VALID_SCORER_SCORE,
9+
} from '../../constants/gitcoin';
10+
11+
const cronJobTime =
12+
(config.get('UPDATE_GITCOIN_SCORES_CRONJOB_EXPRESSION') as string) ||
13+
'0 */6 * * *'; // Run every 6 hours by default
14+
15+
export const runUpdateGitcoinScoresJob = () => {
16+
logger.debug(
17+
'runUpdateGitcoinScoresJob() has been called, cronJobTime',
18+
cronJobTime,
19+
);
20+
21+
schedule(cronJobTime, async () => {
22+
try {
23+
// Find users who skipped verification and have insufficient scores
24+
const users = await User.createQueryBuilder('user')
25+
.where('user.skipVerification = :skipVerification', {
26+
skipVerification: true,
27+
})
28+
.andWhere(
29+
'(user.analysisScore < :minAnalysisScore OR user.passportScore < :minPassportScore)',
30+
{
31+
minAnalysisScore: GITCOIN_PASSPORT_MIN_VALID_ANALYSIS_SCORE,
32+
minPassportScore: GITCOIN_PASSPORT_MIN_VALID_SCORER_SCORE,
33+
},
34+
)
35+
.getMany();
36+
37+
logger.debug(`Found ${users.length} users to update Gitcoin scores`);
38+
39+
// Update scores for each user
40+
for (const user of users) {
41+
try {
42+
await updateUserGitcoinScores(user);
43+
logger.debug(
44+
`Successfully updated Gitcoin scores for user ${user.id}`,
45+
);
46+
} catch (error) {
47+
logger.error(
48+
`Failed to update Gitcoin scores for user ${user.id}:`,
49+
error,
50+
);
51+
}
52+
}
53+
} catch (error) {
54+
logger.error('Error in updateGitcoinScoresJob:', error);
55+
}
56+
});
57+
};

0 commit comments

Comments
 (0)