1- import { Workload } from "./types.js" ;
2- import { prisma } from "./prisma.js" ;
1+ import { Settings , Workload } from "./types.js" ;
32import { ConnectionConfig } from "@sourcebot/schemas/v3/index.type" ;
43import { compileAzureDevOpsConfig , compileBitbucketConfig , compileGenericGitHostConfig , compileGerritConfig , compileGiteaConfig , compileGithubConfig , compileGitlabConfig } from "./repoCompileUtils.js" ;
54import { CONNECTION_QUEUE , env , loadConfig } from "@sourcebot/shared" ;
65import { syncSearchContexts } from "./ee/syncSearchContexts.js" ;
76import * as Sentry from "@sentry/node" ;
7+ import { PrismaClient } from "@sourcebot/db" ;
88
9- export const connectionWorkload : Workload < 'connection' > = {
9+ interface Props {
10+ db : PrismaClient ,
11+ settings : Settings ;
12+ }
13+
14+ export const createConnectionWorkload = ( {
15+ db,
16+ settings
17+ } : Props ) : Workload < 'connection' > => ( {
1018 queueSpec : CONNECTION_QUEUE ,
11- concurrency : 2 ,
19+ concurrency : settings . maxConnectionSyncJobConcurrency ,
1220 process : async ( {
1321 data : {
1422 connectionId,
@@ -21,7 +29,7 @@ export const connectionWorkload: Workload<'connection'> = {
2129 connectionId,
2230 orgId,
2331 } ) ;
24- const connection = await prisma . connection . findUniqueOrThrow ( {
32+ const connection = await db . connection . findUniqueOrThrow ( {
2533 where : {
2634 id : connectionId
2735 }
@@ -55,7 +63,7 @@ export const connectionWorkload: Workload<'connection'> = {
5563 // captured by the connection's config (e.g., it was deleted, marked archived, etc.), it won't
5664 // appear in the repoData array above, and so the RepoToConnection record won't be re-created.
5765 // Repos that have no RepoToConnection records are considered orphaned and can be deleted.
58- await prisma . $transaction ( async ( tx ) => {
66+ await db . $transaction ( async ( tx ) => {
5967 const deleteStart = performance . now ( ) ;
6068 await tx . connection . update ( {
6169 where : {
@@ -104,7 +112,7 @@ export const connectionWorkload: Workload<'connection'> = {
104112 } ) ;
105113 } , { timeout : env . CONNECTION_MANAGER_UPSERT_TIMEOUT_MS } ) ;
106114
107- await prisma . connection . update ( {
115+ await db . connection . update ( {
108116 where : {
109117 id : connectionId ,
110118 } ,
@@ -131,7 +139,7 @@ export const connectionWorkload: Workload<'connection'> = {
131139 connectionId,
132140 } ) ;
133141 }
134- }
142+ } )
135143
136144const discoverConnectionRepositories = async ( {
137145 config,
0 commit comments