1
- import { Connection , ConnectionSyncStatus , PrismaClient , Prisma , Repo } from "@sourcebot/db" ;
1
+ import { Connection , ConnectionSyncStatus , PrismaClient , Prisma } from "@sourcebot/db" ;
2
2
import { Job , Queue , Worker } from 'bullmq' ;
3
- import { Settings , WithRequired } from "./types.js" ;
3
+ import { Settings } from "./types.js" ;
4
4
import { ConnectionConfig } from "@sourcebot/schemas/v3/connection.type" ;
5
5
import { createLogger } from "./logger.js" ;
6
6
import os from 'os' ;
@@ -24,7 +24,7 @@ type JobPayload = {
24
24
} ;
25
25
26
26
type JobResult = {
27
- repoCount : number
27
+ repoCount : number ,
28
28
}
29
29
30
30
export class ConnectionManager implements IConnectionManager {
@@ -82,7 +82,7 @@ export class ConnectionManager implements IConnectionManager {
82
82
} , this . settings . resyncConnectionPollingIntervalMs ) ;
83
83
}
84
84
85
- private async runSyncJob ( job : Job < JobPayload > ) {
85
+ private async runSyncJob ( job : Job < JobPayload > ) : Promise < JobResult > {
86
86
const { config, orgId } = job . data ;
87
87
// @note : We aren't actually doing anything with this atm.
88
88
const abortController = new AbortController ( ) ;
@@ -105,6 +105,7 @@ export class ConnectionManager implements IConnectionManager {
105
105
id : job . data . connectionId ,
106
106
} ,
107
107
data : {
108
+ syncStatus : ConnectionSyncStatus . SYNCING ,
108
109
syncStatusMetadata : { }
109
110
}
110
111
} )
@@ -233,12 +234,25 @@ export class ConnectionManager implements IConnectionManager {
233
234
this . logger . info ( `Connection sync job ${ job . id } completed` ) ;
234
235
const { connectionId } = job . data ;
235
236
237
+ let syncStatusMetadata : Record < string , unknown > = ( await this . db . connection . findUnique ( {
238
+ where : { id : connectionId } ,
239
+ select : { syncStatusMetadata : true }
240
+ } ) ) ?. syncStatusMetadata as Record < string , unknown > ?? { } ;
241
+ const { notFound } = syncStatusMetadata as { notFound : {
242
+ users : string [ ] ,
243
+ orgs : string [ ] ,
244
+ repos : string [ ] ,
245
+ } } ;
246
+
236
247
await this . db . connection . update ( {
237
248
where : {
238
249
id : connectionId ,
239
250
} ,
240
251
data : {
241
- syncStatus : ConnectionSyncStatus . SYNCED ,
252
+ syncStatus :
253
+ notFound . users . length > 0 ||
254
+ notFound . orgs . length > 0 ||
255
+ notFound . repos . length > 0 ? ConnectionSyncStatus . SYNCED_WITH_WARNINGS : ConnectionSyncStatus . SYNCED ,
242
256
syncedAt : new Date ( )
243
257
}
244
258
} )
0 commit comments