remove transaction for job creation

This commit is contained in:
bkellam 2025-10-29 23:42:53 -07:00
parent 26a7555f53
commit bad7757a62
2 changed files with 37 additions and 35 deletions

View file

@ -110,24 +110,25 @@ export class RepoPermissionSyncer {
} }
private async schedulePermissionSync(repos: Repo[]) { private async schedulePermissionSync(repos: Repo[]) {
await this.db.$transaction(async (tx) => { // @note: we don't perform this in a transaction because
const jobs = await tx.repoPermissionSyncJob.createManyAndReturn({ // we want to avoid the situation where a job is created and run
data: repos.map(repo => ({ // prior to the transaction being committed.
repoId: repo.id, const jobs = await this.db.repoPermissionSyncJob.createManyAndReturn({
})), data: repos.map(repo => ({
}); repoId: repo.id,
})),
await this.queue.addBulk(jobs.map((job) => ({
name: 'repoPermissionSyncJob',
data: {
jobId: job.id,
},
opts: {
removeOnComplete: env.REDIS_REMOVE_ON_COMPLETE,
removeOnFail: env.REDIS_REMOVE_ON_FAIL,
}
})))
}); });
await this.queue.addBulk(jobs.map((job) => ({
name: 'repoPermissionSyncJob',
data: {
jobId: job.id,
},
opts: {
removeOnComplete: env.REDIS_REMOVE_ON_COMPLETE,
removeOnFail: env.REDIS_REMOVE_ON_FAIL,
}
})))
} }
private async runJob(job: Job<RepoPermissionSyncJob>) { private async runJob(job: Job<RepoPermissionSyncJob>) {

View file

@ -6,7 +6,7 @@ import { Redis } from "ioredis";
import { PERMISSION_SYNC_SUPPORTED_CODE_HOST_TYPES } from "../constants.js"; import { PERMISSION_SYNC_SUPPORTED_CODE_HOST_TYPES } from "../constants.js";
import { env } from "../env.js"; import { env } from "../env.js";
import { createOctokitFromToken, getReposForAuthenticatedUser } from "../github.js"; import { createOctokitFromToken, getReposForAuthenticatedUser } from "../github.js";
import { createGitLabFromOAuthToken, createGitLabFromPersonalAccessToken, getProjectsForAuthenticatedUser } from "../gitlab.js"; import { createGitLabFromOAuthToken, getProjectsForAuthenticatedUser } from "../gitlab.js";
import { hasEntitlement } from "@sourcebot/shared"; import { hasEntitlement } from "@sourcebot/shared";
import { Settings } from "../types.js"; import { Settings } from "../types.js";
@ -113,24 +113,25 @@ export class UserPermissionSyncer {
} }
private async schedulePermissionSync(users: User[]) { private async schedulePermissionSync(users: User[]) {
await this.db.$transaction(async (tx) => { // @note: we don't perform this in a transaction because
const jobs = await tx.userPermissionSyncJob.createManyAndReturn({ // we want to avoid the situation where a job is created and run
data: users.map(user => ({ // prior to the transaction being committed.
userId: user.id, const jobs = await this.db.userPermissionSyncJob.createManyAndReturn({
})), data: users.map(user => ({
}); userId: user.id,
})),
await this.queue.addBulk(jobs.map((job) => ({
name: 'userPermissionSyncJob',
data: {
jobId: job.id,
},
opts: {
removeOnComplete: env.REDIS_REMOVE_ON_COMPLETE,
removeOnFail: env.REDIS_REMOVE_ON_FAIL,
}
})))
}); });
await this.queue.addBulk(jobs.map((job) => ({
name: 'userPermissionSyncJob',
data: {
jobId: job.id,
},
opts: {
removeOnComplete: env.REDIS_REMOVE_ON_COMPLETE,
removeOnFail: env.REDIS_REMOVE_ON_FAIL,
}
})))
} }
private async runJob(job: Job<UserPermissionSyncJob>) { private async runJob(job: Job<UserPermissionSyncJob>) {