feat: migrate db to postgres

This commit is contained in:
2024-08-09 22:17:09 +07:00
parent 0142224f60
commit 8ff59ba6b3
18 changed files with 462 additions and 215 deletions
+9 -3
View File
@@ -22,13 +22,15 @@ export const fetchRepoContributors = async (
throw new Error("Repository not found!");
}
if (!repo.userAccessToken) {
const accessToken =
repo.userAccessToken || import.meta.env.GITHUB_DEFAULT_TOKEN;
if (!accessToken) {
throw new Error("User access token not found!");
}
const contributors = await github.getRepoContributors(data.uri, {
headers: {
Authorization: `Bearer ${repo.userAccessToken}`,
Authorization: `Bearer ${accessToken}`,
},
});
@@ -42,7 +44,11 @@ export const fetchRepoContributors = async (
throw new Error("Cannot update repository!");
}
await queue.add("calculateUserPoints", { userId: result.userId });
await queue.add(
"calculateUserPoints",
{ userId: result.userId },
{ jobId: `calculateUserPoints:${result.userId}` }
);
};
export const onFetchRepoContribFailed = async (
+5 -1
View File
@@ -61,5 +61,9 @@ export const fetchRepoData = async (data: FetchRepoDataJobType) => {
}
});
await queue.add("calculateUserPoints", { userId: repository.userId });
await queue.add(
"calculateUserPoints",
{ userId: repository.userId },
{ jobId: `calculateUserPoints:${repository.userId}` }
);
};
+5 -1
View File
@@ -27,5 +27,9 @@ export const fetchUserProfile = async (data: FetchUserProfileType) => {
})
.where(eq(users.id, user.id));
await queue.add("calculateUserPoints", { userId: user.id });
await queue.add(
"calculateUserPoints",
{ userId: user.id },
{ jobId: `calculateUserPoints:${user.id}` }
);
};
+1 -1
View File
@@ -62,7 +62,7 @@ export const fetchUserRepos = async (data: FetchUserRepos) => {
data,
opts: {
attempts: 5,
backoff: { type: "exponential", delay: 30000 },
backoff: { type: "exponential", delay: 3000 },
jobId: `contributors:${data.uri}`,
},
}))